#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
int pre[MAXN], suf[MAXN];
string s, tmp;
int main() {
  cin >> n >> tmp;
  s = " " + tmp;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'G') {
      pre[i] = pre[i - 1] + 1;
      if (s[i - 1] != 'G') ++cnt;
    }
  }
  for (int i = n; i >= 1; --i) {
    if (s[i] == 'G') {
      suf[i] = suf[i + 1] + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'S') {
      if (s[i - 1] == 'G' && s[i + 1] == 'G') {
        ans = max(ans, pre[i - 1] + suf[i + 1] + (int)(cnt > 2));
      } else {
        ans = max(ans, pre[i - 1] + suf[i + 1] + (int)(cnt >= 2));
      }
    }
  }
  if (ans)
    cout << ans << endl;
  else {
    for (int i = 1; i <= n; ++i) {
      ans = max(ans, pre[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
