#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long inf = 4e18;
const long long N = 5e5 + 5;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tt = 1;
  while (tt--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long ng = 0;
    for (auto x : s)
      if (x == 'G') ng++;
    vector<long long> pre(n), suf(n);
    for (long long i = 0; i < n; ++i)
      if (s[i] == 'G') pre[i] = suf[i] = 1;
    for (long long i = 1; i < n; ++i)
      if (s[i] == 'G') pre[i] = pre[i - 1] + 1;
    for (long long i = n - 2; i >= 0; --i)
      if (s[i] == 'G') suf[i] = suf[i + 1] + 1;
    long long maxx = *max_element(begin(pre), end(pre));
    maxx = max(maxx, *max_element(begin(suf), end(suf)));
    if (maxx != (ng)) maxx++;
    for (long long i = 1; i <= n - 2; ++i) {
      if (s[i - 1] == 'G' && s[i + 1] == 'G' && s[i] == 'S')
        maxx =
            max(maxx, pre[i - 1] + suf[i + 1] < ng ? pre[i - 1] + suf[i + 1] + 1
                                                   : pre[i - 1] + suf[i + 1]);
    }
    cout << maxx << "\n";
  }
  return 0;
}
