#include <bits/stdc++.h>
using namespace std;
long long expo(long long a, long long b, long long m) {
  if (a == 0) return 1;
  long long res = 1;
  while (b) {
    if (b % 2 == 1) res = ((res % m) * (a % m)) % m;
    a = ((a % m) * (a % m)) % m;
    b /= 2;
  }
  return res % m;
}
long double expo2(long double a, long long b) {
  long double res = 1;
  while (b) {
    if (b % 2 == 1) res = (res * a);
    a = (a * a);
    b /= 2;
  }
  return res;
}
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long i, cnt = 0;
  vector<pair<long long, long long>> v;
  for (i = 0; i <= n - 1; i++) {
    if (s[i] == 'G')
      cnt++;
    else {
      if (cnt) v.push_back(make_pair(cnt, i - 1));
      cnt = 0;
    }
  }
  if (cnt) v.push_back(make_pair(cnt, i - 1));
  long long ans = 0, l = v.size();
  for (auto e : v) {
    if (l > 1)
      ans = max(ans, e.first + 1);
    else
      ans = max(ans, e.first);
  }
  for (i = 0; i < l - 1; i++) {
    if (s[v[i].second + 2] == 'G') {
      if (l > 2)
        ans = max(v[i].first + v[i + 1].first + 1, ans);
      else
        ans = max(ans, v[i].first + v[i + 1].first);
    }
  }
  cout << ans;
  return 0;
}
