#include <bits/stdc++.h>
using namespace std;
long long int i, j, k, sum = 0, ans = 0, n;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve() {
  cin >> n;
  vector<int> l(n), r(n);
  string s;
  cin >> s;
  for (int i = 0; i < int(n); i++) {
    if (s[i] == 'G') {
      l[i] = 1;
      if (i > 0) l[i] += l[i - 1];
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if (s[i] == 'G') {
      r[i] = 1;
      if (i < n - 1) r[i] += r[i + 1];
    }
  }
  long long int pans = 0, cntG = 0;
  i = 0;
  while (i < n) {
    if (s[i] == 'G') cntG++;
    i++;
  }
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'G') continue;
    pans = 1;
    if (i > 0) pans += l[i - 1];
    if (i < n - 1) pans += r[i + 1];
    ans = max(ans, pans);
  }
  ans = min(ans, cntG);
  if (cntG == n) ans = n;
  cout << ans;
}
int main() {
  fastio();
  int t = 1;
  while (t--) solve();
  return 0;
}
