#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> l(n, 0), r(n, 0);
  long long t = 0, p = 0, flag = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'G') flag++;
    l[i] = t;
    r[n - 1 - i] = p;
    if (s[i] == 'G')
      t++;
    else
      t = 0;
    if (s[n - 1 - i] == 'G')
      p++;
    else
      p = 0;
  }
  long long mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, 1 + l[i] + r[i]);
  }
  if (!flag) mx = 0;
  if (mx > flag) mx = flag;
  cout << mx;
}
