	/*input

	*/
	import java.io.ByteArrayInputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.PrintWriter;
	import java.util.*;
	public class Main {
	InputStream is;
		PrintWriter out;
		String INPUT = "";
	//class Declaration
	static class pair implements Comparable<pair>{
		int x,y;

		pair (int i,int j)
		{ x=i; y=j;

		}
		public int compareTo(pair p){
			if(this.x!=p.x) { return this.x-p.x;}
			else { return this.y-p.y;}
		}
		public int hashCode() { return (x+" "+y).hashCode();}
		public String toString(){ return x+" "+y;}
		public boolean equals(Object o){
			pair x = (pair) o ;
			return (x.x==this.x&&x.y==this.y);}
	}

void solve(){
int n=ni();
char str[] =ns().toCharArray();
ArrayList<Character> modified= new ArrayList<>();
ArrayList<Integer> count = new ArrayList<>();
char prev='@';
int cnt=1;
int sz=0;
for(int i=0;i<n;++i){
	if(str[i]==prev){
		cnt++;
		count.set(sz-1,cnt);
	}
	else{
		cnt=1;
		modified.add(str[i]);
		count.add(cnt);
		sz++;
		prev=str[i];

	}
}
//pn(modified);
//pn(count);
int ans=0;
//pn("sze "+sz);
for(int i=0;i<sz;++i){
	if(modified.get(i)=='S' && count.get(i)==1){
		if(i-1>=0 && i+1<sz){
			//pn("i "+i);
			ans = Math.max(ans,count.get(i-1)+count.get(i+1));
			//pn(count.get(i-1)+" "+count.get(i+1));
			if(i+3<sz || i-3>=0) ans=Math.max(ans,count.get(i-1)+count.get(i+1)+1);

		}
	}
	else {
		if(modified.get(i)=='G'){
			ans= Math.max(ans,count.get(i));
			if(i+2<sz){
				ans = Math.max(ans,1+count.get(i));
			}
			if(i-2>=0){
				ans = Math.max(ans,1+count.get(i));
			}

		}
	}
}

pn(ans);

}

int gcd(int a, int b)
{
  if (b == 0)
	return a;
  return gcd(b, a % b);
}

	void run() throws Exception
	{
			is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
			out = new PrintWriter(System.out);

			long s = System.currentTimeMillis();
			solve();
			out.flush();
			if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

		public static void main(String[] args) throws Exception { new Main().run(); }

	//output methods
	private void pn(Object o)
	{
		out.println(o);
	}
	private void p(Object o)
	{
		out.print(o);
	}

	//input methods
			private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte()
		{
			if(lenbuf == -1)throw new InputMismatchException();
			if(ptrbuf >= lenbuf){
				ptrbuf = 0;
				try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
				if(lenbuf <= 0)return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
		private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

		private double nd() { return Double.parseDouble(ns()); }
		private char nc() { return (char)skip(); }

		private String ns()
		{
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n)
		{
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while(p < n && !(isSpaceChar(b))){
				buf[p++] = (char)b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m)
		{
			char[][] map = new char[n][];
			for(int i = 0;i < n;i++)map[i] = ns(m);
			return map;
		}

		private int[] na(int n)
		{
			int[] a = new int[n];
			for(int i = 0;i < n;i++)a[i] = ni();
			return a;
		}

		private int ni()
		{
			int num = 0, b;
			boolean minus = false;
			while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
			if(b == '-'){
				minus = true;
				b = readByte();
			}

			while(true){
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl()
		{
			long num = 0;
			int b;
			boolean minus = false;
			while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
			if(b == '-'){
				minus = true;
				b = readByte();
			}

			while(true){
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
	}


	/*input

	*/
	import java.io.ByteArrayInputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.PrintWriter;
	import java.util.*;
	public class Main {
	InputStream is;
		PrintWriter out;
		String INPUT = "";
	//class Declaration
	static class pair implements Comparable<pair>{
		int x,y;

		pair (int i,int j)
		{ x=i; y=j;

		}
		public int compareTo(pair p){
			if(this.x!=p.x) { return this.x-p.x;}
			else { return this.y-p.y;}
		}
		public int hashCode() { return (x+" "+y).hashCode();}
		public String toString(){ return x+" "+y;}
		public boolean equals(Object o){
			pair x = (pair) o ;
			return (x.x==this.x&&x.y==this.y);}
	}

void solve(){
int n=ni();
char str[] =ns().toCharArray();
ArrayList<Character> modified= new ArrayList<>();
ArrayList<Integer> count = new ArrayList<>();
char prev='@';
int cnt=1;
int sz=0;
for(int i=0;i<n;++i){
	if(str[i]==prev){
		cnt++;
		count.set(sz-1,cnt);
	}
	else{
		cnt=1;
		modified.add(str[i]);
		count.add(cnt);
		sz++;
		prev=str[i];

	}
}
//pn(modified);
//pn(count);
int ans=0;
//pn("sze "+sz);
for(int i=0;i<sz;++i){
	if(modified.get(i)=='S' && count.get(i)==1){
		if(i-1>=0 && i+1<sz){
			//pn("i "+i);
			ans = Math.max(ans,count.get(i-1)+count.get(i+1));
			//pn(count.get(i-1)+" "+count.get(i+1));
			if(i+3<sz || i-3>=0) ans=Math.max(ans,count.get(i-1)+count.get(i+1)+1);

		}
	}
	else {
		if(modified.get(i)=='G'){
			ans= Math.max(ans,count.get(i));
			if(i+2<sz){
				ans = Math.max(ans,count.get(i+2)+count.get(i));
			}

		}
	}
}

pn(ans);

}

int gcd(int a, int b)
{
  if (b == 0)
	return a;
  return gcd(b, a % b);
}

	void run() throws Exception
	{
			is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
			out = new PrintWriter(System.out);

			long s = System.currentTimeMillis();
			solve();
			out.flush();
			if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

		public static void main(String[] args) throws Exception { new Main().run(); }

	//output methods
	private void pn(Object o)
	{
		out.println(o);
	}
	private void p(Object o)
	{
		out.print(o);
	}

	//input methods
			private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte()
		{
			if(lenbuf == -1)throw new InputMismatchException();
			if(ptrbuf >= lenbuf){
				ptrbuf = 0;
				try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
				if(lenbuf <= 0)return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
		private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

		private double nd() { return Double.parseDouble(ns()); }
		private char nc() { return (char)skip(); }

		private String ns()
		{
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n)
		{
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while(p < n && !(isSpaceChar(b))){
				buf[p++] = (char)b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m)
		{
			char[][] map = new char[n][];
			for(int i = 0;i < n;i++)map[i] = ns(m);
			return map;
		}

		private int[] na(int n)
		{
			int[] a = new int[n];
			for(int i = 0;i < n;i++)a[i] = ni();
			return a;
		}

		private int ni()
		{
			int num = 0, b;
			boolean minus = false;
			while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
			if(b == '-'){
				minus = true;
				b = readByte();
			}

			while(true){
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl()
		{
			long num = 0;
			int b;
			boolean minus = false;
			while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
			if(b == '-'){
				minus = true;
				b = readByte();
			}

			while(true){
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
	}


	/*input

	*/
	import java.io.ByteArrayInputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.PrintWriter;
	import java.util.*;
	public class Main {
	InputStream is;
		PrintWriter out;
		String INPUT = "";
	//class Declaration
	static class pair implements Comparable<pair>{
		int x,y;

		pair (int i,int j)
		{ x=i; y=j;

		}
		public int compareTo(pair p){
			if(this.x!=p.x) { return this.x-p.x;}
			else { return this.y-p.y;}
		}
		public int hashCode() { return (x+" "+y).hashCode();}
		public String toString(){ return x+" "+y;}
		public boolean equals(Object o){
			pair x = (pair) o ;
			return (x.x==this.x&&x.y==this.y);}
	}

void solve(){
int n=ni();
char str[] =ns().toCharArray();
ArrayList<Character> modified= new ArrayList<>();
ArrayList<Integer> count = new ArrayList<>();
char prev='@';
int cnt=1;
int sz=0;
for(int i=0;i<n;++i){
	if(str[i]==prev){
		cnt++;
		count.set(sz-1,cnt);
	}
	else{
		cnt=1;
		modified.add(str[i]);
		count.add(cnt);
		sz++;
		prev=str[i];

	}
}
//pn(modified);
//pn(count);
int ans=0;
//pn("sze "+sz);
for(int i=0;i<sz;++i){
	if(modified.get(i)=='S' && count.get(i)==1){
		if(i-1>=0 && i+1<sz){
			//pn("i "+i);
			ans = Math.max(ans,count.get(i-1)+count.get(i+1));
			//pn(count.get(i-1)+" "+count.get(i+1));
			if(i+3<sz || i-3>=0) ans=Math.max(ans,count.get(i-1)+count.get(i+1)+1);

		}
	}
	else {
		if(modified.get(i)=='G') ans = Math.max(count.get(i),ans);
	}
}

pn(ans);

}

int gcd(int a, int b)
{
  if (b == 0)
	return a;
  return gcd(b, a % b);
}

	void run() throws Exception
	{
			is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
			out = new PrintWriter(System.out);

			long s = System.currentTimeMillis();
			solve();
			out.flush();
			if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

		public static void main(String[] args) throws Exception { new Main().run(); }

	//output methods
	private void pn(Object o)
	{
		out.println(o);
	}
	private void p(Object o)
	{
		out.print(o);
	}

	//input methods
			private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte()
		{
			if(lenbuf == -1)throw new InputMismatchException();
			if(ptrbuf >= lenbuf){
				ptrbuf = 0;
				try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
				if(lenbuf <= 0)return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
		private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

		private double nd() { return Double.parseDouble(ns()); }
		private char nc() { return (char)skip(); }

		private String ns()
		{
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n)
		{
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while(p < n && !(isSpaceChar(b))){
				buf[p++] = (char)b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m)
		{
			char[][] map = new char[n][];
			for(int i = 0;i < n;i++)map[i] = ns(m);
			return map;
		}

		private int[] na(int n)
		{
			int[] a = new int[n];
			for(int i = 0;i < n;i++)a[i] = ni();
			return a;
		}

		private int ni()
		{
			int num = 0, b;
			boolean minus = false;
			while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
			if(b == '-'){
				minus = true;
				b = readByte();
			}

			while(true){
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl()
		{
			long num = 0;
			int b;
			boolean minus = false;
			while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
			if(b == '-'){
				minus = true;
				b = readByte();
			}

			while(true){
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
	}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class b1082 {
    public static void main (String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        int size = Integer.parseInt(inp.readLine());
        String[] s1 = inp.readLine().split("");
        ArrayList<Integer> amount = new ArrayList<>();
        int gold = 0;
        int silver = 0;
        int groupGold = 0;
        for(int i=0;i<size;i++){
            if(s1[i].equals("G") && gold==0){
                amount.add(silver);
                groupGold++;
            }
            if(s1[i].equals("S") && silver==0){

                amount.add(gold);
            }
            if(s1[i].equals("G")){
                gold++;
                silver=0;
            }else {
                silver--;
                gold = 0;
            }
        }
        if( gold==0){
            amount.add(silver);
        }
        if(silver==0){
            groupGold++;
            amount.add(gold);
        }
        amount.add(0);

//        System.out.println(amount);
//        System.out.println(groupGold);
        if(groupGold>=3){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1)+1);
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i));
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==2){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1));
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i)+1);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==1){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)>0){
                    maxSum = amount.get(i);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==0){
            System.out.println(0);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class b1082 {
    public static void main (String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        int size = Integer.parseInt(inp.readLine());
        String[] s1 = inp.readLine().split("");
        ArrayList<Integer> amount = new ArrayList<>();
        int gold = 0;
        int silver = 0;
        int groupGold = 0;
        for(int i=0;i<size;i++){
            if(s1[i].equals("G") && gold==0){
                amount.add(silver);
            }
            if(s1[i].equals("S") && silver==0){

                amount.add(gold);
            }
            if(s1[i].equals("G")){
                gold++;
                silver=0;
            }else {
                silver--;
                gold = 0;
            }
        }
        if( gold==0){
            amount.add(silver);
        }
        if(silver==0){
            amount.add(gold);
        }
        for(int i=0;i<amount.size();i++){
            if(amount.get(i)>0){
                groupGold++;
            }
        }
        amount.add(0);

//        System.out.println(amount);
//        System.out.println(groupGold);
        if(groupGold>=3){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1)+1);
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i));
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==2){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1));
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i)+1);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==1){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)>0){
                    maxSum = amount.get(i);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==0){
            System.out.println(0);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class b1082 {
    public static void main (String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        int size = Integer.parseInt(inp.readLine());
        String[] s1 = inp.readLine().split("");
        ArrayList<Integer> amount = new ArrayList<>();
        int gold = 0;
        int silver = 0;
        int groupGold = 0;
        for(int i=0;i<size;i++){
            if(s1[i].equals("G") && gold==0){
                amount.add(silver);
            }
            if(s1[i].equals("S") && silver==0){

                amount.add(gold);
            }
            if(s1[i].equals("G")){
                gold++;
                silver=0;
            }else {
                silver--;
                gold = 0;
            }
        }
        if( gold==0){
            amount.add(silver);
        }
        if(silver==0){
            amount.add(gold);
        }
        for(int i=0;i<amount.size();i++){
            if(amount.get(i)>0){
                groupGold++;
            }
        }
        amount.add(0);

//        System.out.println(amount);
//        System.out.println(groupGold);
        if(groupGold>=3){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1)+1);
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i)+1);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==2){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1));
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i)+1);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==1){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)>0){
                    maxSum = amount.get(i);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==0){
            System.out.println(0);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class b1082 {
    public static void main (String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        int size = Integer.parseInt(inp.readLine());
        String[] s1 = inp.readLine().split("");
        ArrayList<Integer> amount = new ArrayList<>();
        int gold = 0;
        int silver = 0;
        int groupGold = 0;
        for(int i=0;i<size;i++){
            if(s1[i].equals("G") && gold==0){
                amount.add(silver);
                groupGold++;
            }
            if(s1[i].equals("S") && silver==0){

                amount.add(gold);
            }
            if(s1[i].equals("G")){
                gold++;
                silver=0;
            }else {
                silver--;
                gold = 0;
            }
        }
        if( gold==0){
            amount.add(silver);
        }
        if(silver==0){
            groupGold++;
            amount.add(gold);
        }
        amount.add(0);

//        System.out.println(amount);
//        System.out.println(groupGold);
        if(groupGold>=3){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1)+1);
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i));
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==2){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1));
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i));
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==1){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)>0){
                    maxSum = amount.get(i);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==0){
            System.out.println(0);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class b1082 {
    public static void main (String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        int size = Integer.parseInt(inp.readLine());
        String[] s1 = inp.readLine().split("");
        ArrayList<Integer> amount = new ArrayList<>();
        int gold = 0;
        int silver = 0;
        int groupGold = 0;
        for(int i=0;i<size;i++){
            if(s1[i].equals("G") && gold==0){
                amount.add(silver);
            }
            if(s1[i].equals("S") && silver==0){
                groupGold++;
                amount.add(gold);
            }
            if(s1[i].equals("G")){
                gold++;
                silver=0;
            }else {
                silver--;
                gold = 0;
            }
        }
        if( gold==0){
            amount.add(silver);
        }
        if(silver==0){
            groupGold++;
            amount.add(gold);
        }
        amount.add(0);

//        System.out.println(amount);
//        System.out.println(groupGold);
        if(groupGold>=3){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = Math.max(maxSum,amount.get(i-1)+amount.get(i+1)+1);
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i));
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==2){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)==-1){
                    maxSum = (amount.get(i-1)+amount.get(i+1))-1;
                }
                else{
                    maxSum = Math.max(maxSum,amount.get(i));
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==1){
            int maxSum = 0;
            for(int i=1;i<amount.size()-1;i++){
                if(amount.get(i)>0){
                    maxSum = amount.get(i);
                }
            }
            System.out.println(maxSum);
        }
        if(groupGold==0){
            System.out.println(0);
        }

    }
}


import javafx.util.Pair;
import org.omg.CORBA.INTERNAL;
import sun.awt.image.ImageWatched;
import sun.reflect.generics.tree.Tree;

import java.lang.reflect.Array;
import java.nio.channels.ScatteringByteChannel;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner s =  new Scanner(System.in);

        int n = s.nextInt();

        String str = s.next();

        int amount = 0;

        List<Pair<Integer, Integer>> list = new ArrayList<>();

        int formal = 0;

        int totG = 0;

        int maximum = 0 ;

        if (str.charAt(n-1) == 'G') {

            n++;

            str = str +'S';
        }
        for (int i = 0; i < n; i++) {

            if (str.charAt(i) == 'G')  {

                totG++;

                amount++;
            }

            else {

                maximum = Math.max(maximum, amount);
                if (formal != 0) {

                    list.add(new Pair<Integer, Integer>(formal, amount));

                    formal = 0;
                }

                if (i != n-1 && str.charAt(i+1) == 'S') {

                    int j = i;
                    for (; j < n && str.charAt(j) == 'S'; j++) ;

                    i = j - 1;

                } else {

                    formal = amount;
                }

                amount = 0;
            }
        }

         for (Pair<Integer, Integer> p : list) {

            int sum = p.getValue() + p.getKey();

            if (sum < totG)  sum++;

            maximum = Math.max(sum ,maximum);
        }

         System.out.println(maximum);

    }

}


import javafx.util.Pair;
import org.omg.CORBA.INTERNAL;
import sun.awt.image.ImageWatched;
import sun.reflect.generics.tree.Tree;

import java.lang.reflect.Array;
import java.nio.channels.ScatteringByteChannel;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner s =  new Scanner(System.in);

        int n = s.nextInt();

        String str = s.next();

        int amount = 0;

        List<Integer> list = new ArrayList<>();

        int formal = 0;

        int totG = 0;

        int maximum = 0 ;

        if (str.charAt(n-1) == 'G') {

            n++;

            str = str +'S';
        }
        for (int i = 0; i < n; i++) {

            if (str.charAt(i) == 'G')  {

                totG++;

                amount++;
            }

            else {

                maximum = Math.max(maximum, amount);
                if (formal != 0) {

                    list.add(formal+ amount);

                    formal = 0;
                }

                if (i != n-1 && str.charAt(i+1) == 'S') {

                    int j = i;
                    for (; j < n && str.charAt(j) == 'S'; j++) ;

                    i = j - 1;

                } else {

                    formal = amount;
                }

                amount = 0;
            }
        }

        if (totG > maximum) {

            maximum++;
        }

         for (Integer sum: list) {

            if (sum < totG)  sum++;

            maximum = Math.max(sum ,maximum);
        }

         System.out.println(maximum);

    }

}


import javafx.util.Pair;
import org.omg.CORBA.INTERNAL;
import sun.awt.image.ImageWatched;
import sun.reflect.generics.tree.Tree;

import java.nio.channels.ScatteringByteChannel;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner s =  new Scanner(System.in);

        int n = s.nextInt();

        String str = s.next();

        List<Integer> segment = new ArrayList<>();

        int amount = 0;

        for (int i = 0; i < n; i++) {

            if (str.charAt(i) == 'G') amount++;

            else {

                if (i == n-1 || str.charAt(i+1) == 'G') {

                    segment.add(amount);

                    amount = 0;

                } else {

                    int j = i;
                    for (;  j < n && str.charAt(j) == 'S' ; j++);
                    i =  j-1;

                }
            }
        }

        if (str.charAt(n-1) == 'G') segment.add(amount);

        int maxIndex = -1;

        int max = 0;

        for (int i = 0; i < segment.size()-1; i++) {

            int now = segment.get(i);

            int next = segment.get(i+1);

            if (now+next > max) max = now+next;
        }

        if (segment.size() == 1) {

            max = segment.get(0);
        }
        if (segment.size() > 2) {

            System.out.println(max + 1);
        } else {

            System.out.println(max);
        }

    }

}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
class Node {
    int l;
    int r;
    public Node(int l,int r){
        this.l=l;
        this.r=r;
    }
}
    void solve() {
        int n=ni();
        char s[]=ns().toCharArray();
        ArrayList<Node> vec=new ArrayList<>();
        int l=-1,r=-1;
        int ans=0;
        int ones=0;
        for(int i=0;i<n;i++){
            if(s[i]=='G'){
                r=i;
                if(l==-1) l=i;
                ones++;
            }else {
                if(l!=-1) {
                    vec.add(new Node(l,r));
                    ans=Math.max(ans,r-l+1);
                    l=-1; r=-1;
                }
            }
        }
        if(l!=-1) {
            vec.add(new Node(l,r));
            ans=Math.max(ans,r-l+1);
        }

        for(int i=0;i<vec.size()-1;i++){
            Node p1=vec.get(i),p2=vec.get(i+1);

            if(p2.l-p1.r==2){

                if(ones-(p2.r-p2.l+1)-(p1.r-p1.l+1)>0) ans=Math.max(ans,(p2.r-p2.l+1)+(p1.r-p1.l+1)+1);
                else ans=Math.max(ans,(p2.r-p2.l+1)+(p1.r-p1.l+1));
            }
        }
        for(Node p : vec){
            if(ones-(p.r-p.l+1)>0) ans=Math.max(p.r-p.l+2,ans);
        }
        pw.println(ans);

    }

    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
class Node {
    int l;
    int r;
    public Node(int l,int r){
        this.l=l;
        this.r=r;
    }
}
    void solve() {
        int n=ni();
        char s[]=ns().toCharArray();
        ArrayList<Node> vec=new ArrayList<>();
        int l=-1,r=-1;
        int ans=0;
        int ones=0;
        for(int i=0;i<n;i++){
            if(s[i]=='G'){
                r=i;
                if(l==-1) l=i;
                ones++;
            }else {
                if(l!=-1) {
                    vec.add(new Node(l,r));
                    ans=Math.max(ans,r-l+1);
                    l=-1; r=-1;
                }
            }
        }
        if(l!=-1) {
            vec.add(new Node(l,r));
            ans=Math.max(ans,r-l+1);
        }

        for(int i=0;i<vec.size()-1;i++){
            Node p1=vec.get(i),p2=vec.get(i+1);

            if(p2.l-p1.r==2){

                if(ones-(p2.r-p2.l+1)-(p1.r-p1.l+1)>0) ans=Math.max(ans,(p2.r-p2.l+1)+(p1.r-p1.l+1)+1);
                else ans=Math.max(ans,(p2.r-p2.l+1)+(p1.r-p1.l+1));
            }
        }
        pw.println(ans);

    }

    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
class Node {
    int l;
    int r;
    public Node(int l,int r){
        this.l=l;
        this.r=r;
    }
}
    void solve() {
        int n=ni();
        char s[]=ns().toCharArray();
        ArrayList<Node> vec=new ArrayList<>();
        int l=-1,r=-1;
        int ans=0;
        int ones=0;
        for(int i=0;i<n;i++){
            if(s[i]=='G'){
                r=i;
                if(l==-1) l=i;
                ones++;
            }else {
                if(l!=-1) {
                    vec.add(new Node(l,r));
                    ans=Math.max(ans,r-l+1);
                }
            }
        }
        if(l!=-1) {
            vec.add(new Node(l,r));
            ans=Math.max(ans,r-l+1);
        }
        for(int i=0;i<vec.size()-1;i++){
            Node p1=vec.get(i),p2=vec.get(i+1);
            if(p2.l-p1.r==1){

                if(ones-(p2.r-p2.l+1)-(p1.r-p1.l+1)>0) ans=Math.max(ans,(p2.r-p2.l+1)+(p1.r-p1.l+1)+1);
                else ans=Math.max(ans,(p2.r-p2.l+1)+(p1.r-p1.l+1));
            }
        }
        pw.println(ans);

    }

    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[])
    {
        FastReader input=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int T=1;
        while(T-->0)
        {
            int n=input.nextInt();
            String s=input.next();
            ArrayList<Integer> list=new ArrayList<>();
            int c=1;
            for(int i=0;i<s.length()-1;i++)
            {
                if(s.charAt(i)!=s.charAt(i+1))
                {
                    list.add(c);
                    c=1;
                }
                else
                {
                    c++;
                }
            }
            list.add(c);
            int index=0;
            if(s.charAt(0)=='S')
            {
                index=1;
            }
                int max=0;
                for(int i=index;i<list.size();i+=2)
                {
                    if(i+1<list.size())
                    {
                        if(list.get(i+1)==1)
                        {
                            if(i+2<list.size())
                            {
                                if(i+4<list.size())
                                {
                                    max=Math.max(max,list.get(i)+list.get(i+2)+1);
                                }
                                else
                                {
                                    max=Math.max(max,list.get(i)+list.get(i+2));
                                }
                            }
                            else
                            {
                                max=Math.max(max,list.get(i));
                            }
                        }
                        else
                        {
                            if(i+2<list.size())
                            {
                                max=Math.max(max,list.get(i)+1);
                                max=Math.max(max,list.get(i+2)+1);
                            }
                            else
                            {
                                max=Math.max(max,list.get(i));
                            }
                        }
                    }
                    else
                    {
                        max=Math.max(max,list.get(i));
                    }
                }
                out.println(max);
        }
        out.close();
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[])
    {
        FastReader input=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int T=1;
        while(T-->0)
        {
            int n=input.nextInt();
            String s=input.next();
            ArrayList<Integer> list=new ArrayList<>();
            int c=1;
            for(int i=0;i<s.length()-1;i++)
            {
                if(s.charAt(i)!=s.charAt(i+1))
                {
                    list.add(c);
                    c=1;
                }
                else
                {
                    c++;
                }
            }
            list.add(c);
            int index=0;
            if(s.charAt(0)=='S')
            {
                index=1;
            }
                int max=0;
                for(int i=index;i<list.size();i+=2)
                {
                    if(i+1<list.size())
                    {
                        if(list.get(i+1)==1)
                        {
                            if(i+2<list.size())
                            {
                                if(i+4<list.size())
                                {
                                    max=Math.max(max,list.get(i)+list.get(i+2)+1);
                                }
                                else
                                {
                                    max=Math.max(max,list.get(i)+list.get(i+2));
                                }
                            }
                            else
                            {
                                max=Math.max(max,list.get(i));
                            }
                        }
                        else
                        {
                            if(i+2<list.size())
                            {
                                max=Math.max(max,list.get(i)+1);
                            }
                            else
                            {
                                max=Math.max(max,list.get(i));
                            }
                        }
                    }
                    else
                    {
                        max=Math.max(max,list.get(i));
                    }
                }
                out.println(max);
        }
        out.close();
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;

public class CodeForces1082B{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String s = input.next();
        int cs = 0, max = 0, cg = 0, res = 0;
        for(int i = 0;i<n;i++){
            if(s.charAt(i) == 'G'){
                max++;
                cg++;
            }
            else{
                cs = cg;
                cg = 0;
            }
            res = Math.max(res,cs+cg+1);
        }
        System.out.println(Math.min(res,max));
    }
}


// package CF1082;

import java.util.ArrayList;
import java.util.Scanner;

public class Q2 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        String str = s.next();
//        int n = str.length();
//        ArrayList<Integer> list = new ArrayList<>();
//        list.add(0);

        int countS = 0;
        int countG = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) == 'S'){
//                list.add(i);
                countS++;
            }else{
                countG++;
            }
        }

        if(countG == 1){
            System.out.println(1);
            return;
        }else if(countG == 0){
            System.out.println(0);
            return;
        }

        if(countS == 0){
            System.out.println(n);
            return;
        }
        if(countS == 1){
            System.out.println(n - 1);
            return;
        }
//        list.add(n+1);
//        str =  str;
        if(str.charAt(0) == 'G'){
            str = "S" + str;
        }
        int ans = Integer.MIN_VALUE;
        int i = 0;
        while(i < n) {
            if(str.charAt(i) == 'S'){
                int count = 0;
                int j = i + 1;
                while(j < n && str.charAt(j) == 'G'){
                    count++;
                    j++;
                }

                if(countG == count){
                    System.out.println(countG);
                    return;
                }

                count++;
                j++;
                while(j < n && str.charAt(j) == 'G'){
                    count++;
                    j++;
                }
                ans = Math.max(ans, count);
                i = j;
            }
        }
        System.out.println(ans);

//        System.out.println(max);

    }
}


// package CF1082;

import java.util.ArrayList;
import java.util.Scanner;

public class Q2 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        String str = s.next();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(0);

        int countS = 0;
        int countG = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) == 'S'){
                list.add(i);
                countS++;
            }else{
                countG++;
            }
        }

        if(countG == 1){
            System.out.println(1);
            return;
        }else if(countG == 0){
            System.out.println(0);
            return;
        }

        if(countS == 0){
            System.out.println(n);
            return;
        }
        if(countS == 1){
            System.out.println(n - 1);
            return;
        }
        list.add(n+1);
        ArrayList<Integer> finalList = new ArrayList<>();
        for (int i = 0; i < list.size() - 1; i++) {
            int k = list.get(i+1) - list.get(i);
            finalList.add(k);
        }

        int max = Integer.MIN_VALUE;
        for (int i = 0; i < finalList.size() - 1; i++) {
            if(finalList.get(i+1) + finalList.get(i) - 1 > max){
                max = finalList.get(i+1) + finalList.get(i) - 1;
            }
        }

        System.out.println(max);

    }
}


// package CF1082;

import java.util.ArrayList;
import java.util.Scanner;

public class Q2 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        String str = s.next();
        int countG = 0;
        int countS = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) == 'G'){
                countG++;
            }else{
                countS++;
            }
        }
        int i = 0;
        str = str + "S";
        int ans = Integer.MIN_VALUE;
        while(i < n){
            if(str.charAt(i) == 'G'){
                int count = 1;
                int j = i + 1;
                while(j < n && str.charAt(j) == 'G'){
                    count++;
                    j++;
                }

                if(count == countG){
                    System.out.println(countG);
                    return;
                }
                i = j;
                j++;
                while(j < n && str.charAt(j) == 'G'){
                    j++;
                    count++;
                }

                if(countG == count){
                    System.out.println(countG);
                    return;
                }else{
                    count++;
                }

                ans = Math.max(ans, count);
            }else{
                i++;
            }
        }

        if(ans == Integer.MIN_VALUE){
            ans = 0;
        }
        System.out.println(ans);
    }
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	string trophies;
	cin >> trophies;

	vector<int *> g_seq_length;

	int g_total_count = 0;
	int *g_count = new (int);
	*g_count = 0;
	for (int i = 0; i < trophies.size(); i++) {
		// cout << "i = " << i << endl;
		if (trophies[i] == 'G') {
			g_total_count++;
			if (*g_count == 0) {
				g_count = new (int);
				*g_count = 0;
			}
			(*g_count)++;
		} else {
			g_count = new (int);
			*g_count = 0;
		}
		g_seq_length.push_back(g_count);
	}

	int max = 0;
	for (int i = 0; i < trophies.size(); i++) {
		int v = *(g_seq_length[i]);
		if (v > max) {
			max = v;
		}

		if (trophies[i] == 'G') {
			continue;
		}

		if (i > 0 && i < trophies.size() - 1) {
			if (trophies[i - 1] == 'G' && trophies[i + 1] == 'G') {
				int l = *(g_seq_length[i - 1]);
				int r = *(g_seq_length[i + 1]);
				if (l + r == g_total_count && l + r > max) {
					max = l + r;
				} else if (l + r < g_total_count &&
					   l + r + 1 > max) {
					max = l + r + 1;
				}
			}
		}
	}
	cout << max << endl;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	string trophies;
	cin >> trophies;

	vector<int *> g_seq_length;

	int g_total_count = 0;
	int *g_count = new (int);
	*g_count = 0;
	for (int i = 0; i < trophies.size(); i++) {
		// cout << "i = " << i << endl;
		if (trophies[i] == 'G') {
			g_total_count++;
			if (*g_count == 0) {
				g_count = new (int);
				*g_count = 0;
			}
			(*g_count)++;
		} else {
			g_count = new (int);
			*g_count = 0;
		}
		g_seq_length.push_back(g_count);
	}

	int max = 0;
	for (int i = 0; i < trophies.size(); i++) {
		int v = *(g_seq_length[i]);
		if (v > max) {
			max = v;
		}

		if (trophies[i] == 'G') {
			continue;
		}

		if (i > 0 && i < trophies.size() - 1) {
			int l = *(g_seq_length[i - 1]);
			int r = *(g_seq_length[i + 1]);
			if (l + r == g_total_count && l + r > max) {
				max = l + r;
			} else if (l + r < g_total_count && l + r + 1 > max) {
				max = l + r + 1;
			}
		}
	}
	cout << max << endl;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	string trophies;
	cin >> trophies;

	vector<int *> g_seq_length;

	int g_total_count;
	int *g_count = new (int);
	*g_count = 0;
	for (int i = 0; i < trophies.size(); i++) {
		// cout << "i = " << i << endl;
		if (trophies[i] == 'G') {
			g_total_count++;
			if (*g_count == 0) {
				g_count = new (int);
				*g_count = 0;
			}
			(*g_count)++;
			// cout << "    *g_count = " << *g_count << endl;
			// cout << "    g_count = " << g_count << endl;
		} else {
			g_count = new (int);
			*g_count = 0;
			// cout << "    *g_count = " << *g_count << endl;
			// cout << "    g_count = " << g_count << endl;
		}
		g_seq_length.push_back(g_count);
	}

	// cout << "COUNT=" << endl;
	// for (int i = 0; i < g_seq_length.size(); i++) {
	// cout << *(g_seq_length[i]) << " ";
	//}
	// cout << endl;

	int max = 0;
	for (int i = 0; i < trophies.size(); i++) {
		int v = *(g_seq_length[i]);
		if (v > max) {
			max = v;
		}

		if (trophies[i] == 'G') {
			continue;
		}

		if (i > 0 && i < trophies.size() - 1) {
			if (trophies[i - 1] == 'G' && trophies[i + 1] == 'G') {
				int l = *(g_seq_length[i - 1]);
				int r = *(g_seq_length[i + 1]);
				if (l + r == g_total_count && l + r > max) {
					max = l + r;
				} else if (l + r < g_total_count &&
					   l + r + 1 > max) {
					max = l + r + 1;
				}
			}
		}
	}
	cout << max << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    string s;

    cin >> n;
    cin >> s;

    int ans = 0;
    int cnt_g = 0, cnt_s = 0, sum_g = 0;

    for (auto p : s)
    {
        if (p == 'G')
        {
            ++cnt_g;
            ++sum_g;
        }
        else
        {
            cnt_s = cnt_g;
            cnt_g = 0;
        }
        ans = max(ans, cnt_g + cnt_s + 1);
    }

    ans = min(ans, sum_g);
    cout << ans << endl;
    return 0;
}
/*
8
SGGSGSGS
*/


#include<bits/stdc++.h>
using namespace std;
char a[100005];
int main()
{
	int n, cnt1 = 0;
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++){
		char c = getchar();
		if (c == 'G'){
			a[i] = 1;
			cnt1++;
		}
		else
			a[i] = 0;
	}
	int res = -1;
	for (int i = 0; i < n; i++)
	{
		int cnt = 0;
		if (a[i] == 1){
			while (a[i] == 1 && i<n)
			{
				i++;
				cnt++;
			}
			cnt++;
			int j = i+1;
			if (a[j] == 1){
				while (a[j] == 1 && j<n)
				{
					j++;
					cnt++;
				}
			}
		}
		res = max(cnt, res);
	}
	res = min(res, cnt1);
	cout << res;
	return 0;
}


//
//  main.cpp
//  vovaandtrophies
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//
//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    cin>>l;
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s-1; i>=0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s-1){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            continue;
        }
        int a = 1;
        if(i>0)
            a = a + q[i-1];
        if(i<s-1)
            a = a + r[i+1];
        if(max<a){
            max = a;
        }

    }
    if(max==0){
        max = 4;
    }
    printf("%d",max);

    return 0;

}


//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    scanf("%s",&l);
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s; i>0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    for(int i = 0; i<s;i++){
        if(l[i]!='G'){
            int a = 1;
            if(i>0)
                a = a + q[i-1];
            if(i+1<s)
                a = a + q[i+1];
            if(max<a){
                max = a;
            }
        }
    }
    printf("%d",max);

}


//
//  main.cpp
//  vovaandtrophies
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//
//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    cin>>l;
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s-1; i>=0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s-1){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    bool b = false;
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            b = true;
            continue;
        }
        int a = 0;
        if(b)
            a = 1;
        if(i>0)
            a = a + q[i-1];
        if(i<s-1)
            a = a + r[i+1];
        if(max<a){
            max = a;
        }
    }
    if(count==s){
        max = s;
    }
    printf("%d",max);

    return 0;

}


//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    scanf("%s",&l);
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s; i>0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    for(int i = 0; i<s;i++){
        if(l[i]!='G'){
            int a = 1;
            if(i>0)
                a = a + q[i-1];
            if(i+1<s)
                a = a + q[i+1];
            if(max<a){
                max = a;
            }
        }
    }
    printf("%d",max);

    return 0;

}


//
//  main.cpp
//  vovaandtrophies
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//
//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    cin>>l;
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s-1; i>=0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s-1){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            continue;
        }
        int a = 1;
        if(i>0)
            a = a + q[i-1];
        if(i<s-1)
            a = a + r[i+1];
        if(max<a){
            max = a;
        }

    }
    if(count==s){
        max = s;
    }
    printf("%d",max);

    return 0;

}


//
//  main.cpp
//  vovaandtrophies
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//
//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    cin>>l;
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s-1; i>=0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s-1){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    bool b = false;
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            b = true;
            continue;
        }
        int a = 0;
        if(b)
            a = 1;
        if(i>0)
            a = a + q[i-1];
        if(i<s-1)
            a = a + r[i+1];
        if(max<a){
            max = a;
        }
    }
    if(count==s){
        max = s;
    }
    if(max>count){
        max = count;
    }
    printf("%d",max);

    return 0;

}


//
//  main.cpp
//  vovaandtrophies
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//
//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    cin>>l;
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s-1; i>=0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s-1){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            continue;
        }
        int a = 1;
        if(i>0)
            a = a + q[i-1];
        if(i<s-1)
            a = a + r[i+1];
        if(max<a){
            max = a;
        }

    }
    printf("%d",max);

    return 0;

}


//
//  main.cpp
//  vovaandtrophies
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//
//
//  vovaandtrophies.cpp
//  Codeforces
//
//  Created by Rahul Chandra on 1/1/19.
//  Copyright © 2019 Rahul Chandra. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int s;
    string l;
    int max = 0;
    int count = 0;
    scanf("%d",&s);
    cin>>l;
    vector<int> q(s), r(s);
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            q[i]= 1;
            count++;
            if(i>0){
                q[i] = q[i] + q[i-1];
            }
        }
    }
    for(int i = s-1; i>=0;i--){
        if(l[i]=='G'){
            r[i]= 1;
            if(i<s-1){
                r[i] = r[i] + r[i+1];
            }
        }
    }
    bool b = false;
    for(int i = 0; i<s;i++){
        if(l[i]=='G'){
            b = true;
            continue;
        }
        int a = 0;
        if(b)
            a = 1;
        if(i>0)
            a = a + q[i-1];
        if(i<s-1)
            a = a + r[i+1];
        if(max<a){
            max = a;
        }
    }
    if(count<=s){
        max = s;
    }
    printf("%d",max);

    return 0;

}


#include <stdio.h>
#include <string.h>
char a[100005];
int n,i,sum,ans,k,t;
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
	scanf("%d",&n);
	scanf("%s",a+1);
	sum=0,ans=0,k=0,t=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]=='G')
		{
			sum++;
			t++;
		}
		else
		{
			k=t;
			t=0;
		}
		ans=max(ans,k+t+1);
	}
	printf("%d\n",min(ans,sum));
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
//	for(int i = 0; i < v.size(); i++)
//	{
//		if(v[i] > 0) ok++;
//	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
		if(v[i] != 0 || (i == v.size() - 2 && v[i + 1] != 0)) ok++;
		sum = max(sum,v[i] + v[i + 1]);
	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 1) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0, ok1 = 0;
	ll sum = 0;
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i] > 0) ok1++;
	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
		if(v[i] != 0 || (i == (int)v.size() - 2 && v[i + 1] != 0)) ok++;
		sum = max(sum,v[i] + v[i + 1]);
	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 1 && ok1 > 2) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
//	for(int i = 0; i < v.size(); i++)
//	{
//		if(v[i] > 0) ok++;
////		else if()
//	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
		if(v[i] + v[i + 1] != 0) ok++;
		if(sum <= v[i] + v[i + 1])
		{
			sum = v[i] + v[i + 1];
//			ind = i + 1;
		}

	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 1) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int arr[n+2], arr1[n+2], arr2[n+2];
	memset(arr,0,sizeof(arr));
	memset(arr1,0,sizeof(arr1));
	memset(arr2,0,sizeof(arr2));
	int cnt = 0, sum = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i - 1] == 'G') arr[i] = 1, cnt++;
	}

	for(int i = 1; i <= n; i++)
	{
		arr1[i] = arr1[i - 1] + 1;
		if(arr[i] == 0) arr1[i] = 0;
	}
	for(int i = n; i >= 1; i--)
	{
		arr2[i] = arr2[i + 1] + 1;
		if(arr[i] == 0) arr2[i] = 0;
	}

	for(int i = 1; i <= n; i++)
	{
		sum = max(sum, arr1[i]);
		sum = max(sum, arr1[i - 1] + arr2[i + 1] + 1);
	}
	cout << min(cnt, sum);
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i] > 0) ok++;
	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
		sum = max(sum,v[i] + v[i + 1]);
	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 2) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
	if(s[0] == 'G') ok++;
	if(ok)
	{
		flag = -1;
		int i1 = 0;
		for(i1 = 1; i1 < n; i1++)
		{
			if(s[i1] == 'S') break;
		}
		i1++;
		for(;i1 + 1 < n; i1++)
		{
			if(s[i1] == 'S' && s[i1 + 1] == 'G') ok++;
		}
	}
	else
	{
		for(int i = 0; i + 1 < n; i++)
		{
			if(s[i] == 'S' && s[i + 1] == 'G') ok++;
		}
	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
//		if(v[i] != 0 || (i == v.size() - 2 && v[i + 1] != 0)) ok++;
		sum = max(sum,v[i] + v[i + 1]);
	}
//	for(int i = 0; i < v.size(); i += 2)
//	{
//		if(i == 0)
//		{
//			if(v[i] != 0 || v[i + 1] != 0) ok++;
//		}
//		else if(v[i + 1] != 0) ok++;
//	}
	if((int)v.size() == 1) sum = v[0];
	if(ok >= 3 || (ok >= 2 && flag == -1)) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
	for(int i = 1; i + 1 < n; i++)
	{
		if(s[i] == 'S' && (s[i - 1] == 'G' || s[i + 1] == 'G')) ok++;
	}
	if(s[0] == 'S' && s[1] == 'G') ok++;
	if(s[n - 1] == 'S' && s[n - 2] == 'G') ok++;
	for(int i = 0; i + 1 < v.size(); i++)
	{
		sum = max(sum,v[i] + v[i + 1]);
	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 1) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
//	for(int i = 0; i < v.size(); i++)
//	{
//		if(v[i] > 0) ok++;
//	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
		if(v[i] != 0) ok++;
		sum = max(sum,v[i] + v[i + 1]);
	}
	if(*v.rbegin() != 0) ok++;
	if((int)v.size() == 1) sum = v[0];
	if(ok > 1) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			if(cnt != 0)v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i] > 0) ok++;
	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
		sum = max(sum,v[i] + v[i + 1]);
	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 2) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
 *  AUTHOR: head_shot_1
 *
 *  "World is changing, stay safe, live safe" - head_shot_1.
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define soa(_x_, a, b) sort(_x_ + a, _x_ + b)
#define sov(_x_) sort(_x_x.begin(), _x_.end())
#define rev(_x_) reverse(_x_.begin(), _x_.end())

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <ll> v;
	int flag = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'S')
		{
			if(i == n - 1) flag = 1;
			v.push_back(cnt);
			cnt = 0;
		}
		else cnt++;
	}
	if(!flag) v.push_back(cnt);
	int ok = 0;
	ll sum = 0;
//	for(int i = 0; i < v.size(); i++)
//	{
//		if(v[i] > 0) ok++;
//	}
	for(int i = 0; i + 1 < v.size(); i++)
	{
//		if(v[i] != 0 || (i == v.size() - 2 && v[i + 1] != 0)) ok++;
		sum = max(sum,v[i] + v[i + 1]);
	}
	for(int i = 0; i < v.size(); i += 2)
	{
		if(i == 0)
		{
			if(v[i] != 0 || v[i + 1] != 0) ok++;
		}
		else if(v[i + 1] != 0) ok++;
	}
	if((int)v.size() == 1) sum = v[0];
	if(ok > 1) cout << sum + 1 << "\n";
	else cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 1; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if((v.size() > 2 && v.size() <= 4) || (v.size()==5 && v[0].first=='S'))
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3 || i==4)
				{
					ans = max(ans,v[i-1].second + 1);
				}
				// continue;
			}
			// else if(v.size()==5 && v[0].first=='S')
			else if(v.size()>4)
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
		else if(v[i].first=='S' && v[i].second !=1)
		{
			if(v.size()>2 && v[0].first=='G')
			{
				ans = max(ans,v[i-1].second + 1);
				if(i!=v.size()-1) ans = max(ans,v[i+1].second +1);
			}
			else if(v.size() > 3 && v[0].first=='S')
			{
				ans = max(ans,v[i-1].second + 1);
				if(i!=v.size()-1) ans = max(ans,v[i+1].second +1);
			}

		}
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 1; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if((v.size() > 2 && v.size() <= 4) || (v.size()==5 && v[0].first=='S'))
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3 || i==4)
				{
					ans = max(ans,v[i-1].second + 1);
				}
				// continue;
			}
			// else if(v.size()==5 && v[0].first=='S')
			else if(v.size()>4)
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
		else if(v[i].first=='S' && v[i].second !=1)
		{
			if(v.size()>2) ans = max(ans,v[i-1].second + 1);
		}
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 0; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if(v.size() > 2 && v.size() <= 4)
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3)
				{
					ans = max(ans,v[i-1].second + 1);
				}
			}
			else if(v.size() > 4)
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 0; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if((v.size() > 2 && v.size() <= 4) || (v.size()==5 && v[0].first=='S'))
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3 || i==4)
				{
					ans = max(ans,v[i-1].second + 1);
				}
				// continue;
			}
			// else if(v.size()==5 && v[0].first=='S')
			else if(v.size()>4)
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 0; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if((v.size() > 2 && v.size() <= 4) || (v.size()==5 && v[0].first=='S'))
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3 || i==4)
				{
					ans = max(ans,v[i-1].second + 1);
				}
				// continue;
			}
			// else if(v.size()==5 && v[0].first=='S')
			else
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 1; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if((v.size() > 2 && v.size() <= 4) || (v.size()==5 && v[0].first=='S'))
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3 || i==4)
				{
					ans = max(ans,v[i-1].second + 1);
				}
				// continue;
			}
			// else if(v.size()==5 && v[0].first=='S')
			else if(v.size()>4)
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
		else if(v[i].first=='S' && v[i].second !=1)
		{
			if(v.size()>2)
			{
				ans = max(ans,v[i-1].second + 1);
				if(i!=v.size()-1) ans = max(ans,v[i+1].second +1);
			}

		}
	}
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(), a.end()
#define dbg(x) cerr << #x"=" << x << endl;
typedef long long int ll;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    	return (a.first - a.second) > (b.first - b.second);
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll power_mod(ll x, ll y,ll mod)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return ((temp%mod)*(temp%mod))%mod;
    else
        return ((x%mod)*((temp%mod)*(temp%mod))%mod)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	std::vector<pair<char,int>> v;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int temp = i;
		int cnt = 0;
		while(s[i]==s[temp] && i < n) i++,cnt++;
		v.pb({s[temp],cnt});
		if(s[temp]=='G') ans = max(ans,cnt);
		i--;
	}
	for (int i = 1; i < v.size(); ++i)
	{
		if(v[i].first=='S' && v[i].second == 1 )
		{
			if((v.size() > 2 && v.size() <= 4) || (v.size()==5 && v[0].first=='S'))
			{
				if(i==0)
				{
					ans = max(ans,v[i+1].second +1);
				}
				if(i==1 || i==2)
				{
					ans = max(ans,v[i-1].second + v[i+1].second);
				}
				if(i==3 || i==4)
				{
					ans = max(ans,v[i-1].second + 1);
				}
				// continue;
			}
			// else if(v.size()==5 && v[0].first=='S')
			else if(v.size()>4)
			{
				if(i!=v.size()-1 && i!=0) ans = max(ans,v[i-1].second + 1 + v[i+1].second);
				else if(i!=0) ans = max(ans,v[i-1].second + 1);
				else ans = max(ans, v[i+1].second + 1);
			}
		}
		else
		{
			if(v.size()>2) ans = max(ans,v[i-1].second + 1);
		}
	}
	cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],suf[N],cnt,cnt1,high,ind = -1,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    suf[n-1] = s[n-1] == 'G';
    for(int i = n-2;i>=0;i--)
        suf[i] = suf[i+1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    ans = max(high,cnt1);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            if(ind == -1)
                ind = i,prefcnt = pref[i];
            else
                ans = max(ans,prefcnt + suf[ind] - suf[i+1] + ((prefcnt + suf[ind] - suf[i+1])<cnt)),ind = i,prefcnt = pref[i];
        }
    }
    cout << min(ans,n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],suf[N],cnt,cnt1,high,ind = -1,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    suf[n-1] = s[n-1] == 'G';
    for(int i = n-2;i>=0;i--)
        suf[i] = suf[i+1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    ans = max(high,cnt1);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            if(ind == -1)
                ind = i,prefcnt = pref[i];
            else
                ans = max(ans,prefcnt + suf[ind] - suf[i+1] + ((prefcnt + suf[ind] - suf[i+1])<cnt)),prefcnt = pref[i] - pref[ind-1],ind = i;
        }
    }
    cout << min(max(ans,prefcnt + suf[ind] + ((prefcnt + suf[ind])<cnt)),n);
    return 0;
}


#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b,c) (v)[(a)].pb({b,c}),(v)[(b)].pb(({a,c}))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;

ll n,pref[N],cnt,cnt1,high,ind = -1,ind1 = -1,ind2,ans,prefcnt;
string s;
int main()
{
    abdelrahman001
    cin >>n >> s;
    pref[0] = cnt = (s[0] == 'G');
    for(int i = 1;i<n;i++)
        cnt+=(s[i] == 'G'),pref[i] = pref[i-1] + (s[i] == 'G');
    for(int i = 0;i<n;i++)
    {
        if(s[i]=='S' && cnt1)
            high= max(high,cnt1),cnt1 = 0;
        cnt1+=s[i] == 'G';
    }
    ans = max(high,cnt1);
    for(int i = 1;i<n-2;i++)
    {
        if(s[i] == 'S' && s[i-1] == 'G' && ~ind)
            ans = max(ans,prefcnt + pref[i] - pref[ind] + ((prefcnt + pref[i] - pref[ind]) < cnt)),ind = -1,ind1 = i;
        if(s[i] == 'S' && s[i-1] == 'G' && s[i+1] == 'G')
        {
            ind = i;
            ll dif = (ind1==-1)?0:pref[ind1-1];
            prefcnt = pref[i] - dif;
        } else if(s[i] == 'S')
            ind1 = i;
    }
    ans = max(ans,prefcnt + pref[n-1] - pref[ind] + ((prefcnt + pref[n-1] - pref[ind]) < cnt));
    cout << min(ans,n);
    return 0;
}