#include <bits/stdc++.h>
using namespace std;
int f(string s, int n) {
  int pre[n];
  for (int i = 0; i < n; i++) pre[i] = 0;
  int c = 0;
  int far = -1, near = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'G') {
      near = i;
      if (far == -1) far = i;
      pre[i] = ++c;
    } else
      pre[i] = c = 0;
  }
  int ans = 0, len = 0;
  bool cv = false;
  if (far != -1)
    for (int i = 0; i < n; i++) {
      if (s[i] == 'G') {
        len++;
        ans = max(ans, len);
      } else {
        cv = true;
        if (far > i) {
          int x = 1;
          if (s[i + 1] == 'G') {
            x += pre[i + 1];
            if (i + pre[i + 1] == far) x--;
          }
          ans = max(ans, len + x);
        } else {
          ans = max(ans, len);
          break;
        }
        len = 0;
      }
    }
  return ans;
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a1 = f(s, n);
  reverse(s.begin(), s.end());
  int a2 = f(s, n);
  cout << max(a1, a2);
  return 0;
}
