#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<pair<int, int> > V;
  int st = -1;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (!cnt && s[i] == 'G') {
      st = i;
      cnt = 1;
    } else if (s[i] == 'G') {
      ++cnt;
    } else if (cnt) {
      V.push_back(make_pair(st, cnt));
      cnt = 0;
    }
  }
  if (cnt) {
    V.push_back(make_pair(st, cnt));
  }
  int ans = 0;
  for (int i = 0; i < V.size(); ++i) {
    ans = max(ans, V[i].second);
    if (V.size() >= 2) {
      ans = max(ans, V[i].second + 1);
    }
    if (i < n - 1) {
      if (V[i].first + V[i].second == V[i + 1].first - 1) {
        ans = max(ans, V[i].second + V[i + 1].second);
        if (V.size() >= 3) {
          ans = max(ans, V[i].second + V[i + 1].second + 1);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
