#include <bits/stdc++.h>
using namespace std;
void deepshit() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  deepshit();
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long pre[n], suf[n];
  long long maxans = 0;
  pre[0] = s[0] == 'G' ? 1 : 0;
  maxans = max(maxans, pre[0]);
  suf[n - 1] = s[n - 1] == 'G' ? 1 : 0;
  maxans = max(maxans, suf[n - 1]);
  for (long long i = 1; i < n; i++) {
    pre[i] = s[i] == 'G' ? pre[i - 1] + 1 : 0;
    maxans = max(maxans, pre[i]);
  }
  for (long long i = n - 2; i >= 0; i--) {
    suf[i] = s[i] == 'G' ? suf[i + 1] + 1 : 0;
    maxans = max(maxans, suf[i]);
  }
  long long gcnt = 0;
  for (long long i = 0; i < n; i++) gcnt = s[i] == 'G' ? gcnt + 1 : gcnt;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'S') {
      if (i == 0) {
        if (suf[i + 1] < gcnt) maxans = max(1 + suf[i + 1], maxans);
      }
      if (i == n - 1) {
        if (pre[i - 1] < gcnt) maxans = max(1 + pre[i - 1], maxans);
      } else {
        if (pre[i - 1] + suf[i + 1] < gcnt)
          maxans = max(maxans, 1 + pre[i - 1] + suf[i + 1]);
        else if (pre[i - 1] + suf[i + 1] == gcnt)
          maxans = max(maxans, pre[i - 1] + suf[i + 1]);
      }
    }
  }
  cout << maxans;
  return 0;
}
