#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int mod = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'G') count++;
  }
  int count1 = 0, temp = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'G') {
      temp++;
      count1 = max(count1, temp);
    } else {
      count1 = max(count1, temp);
      temp = 0;
    }
    count1 = max(count1, temp);
  }
  if (count1 < count)
    count1++;
  else {
    cout << count << '\n';
    return 0;
  }
  vector<int> v1;
  vector<int> v2;
  temp = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'G') {
      if (i == n - 1) {
        v1.push_back(i);
      }
      temp++;
      if (temp == 1) {
        v2.push_back(i);
      }
    } else {
      if (temp != 0) v1.push_back(i - 1);
      temp = 0;
    }
  }
  for (int i = 0; i < v1.size() - 1; ++i) {
    if (abs(v1[i] - v2[i + 1]) == 2) {
      count1 =
          max(count1, (v1[i] - v2[i]) + 1 + 1 + (v1[i + 1] - v2[i + 1]) + 1);
    }
  }
  cout << min(count1, count) << '\n';
  return 0;
}
