#include <bits/stdc++.h>
const double Pi = 3.14159265;
const int N = 1e5 + 5;
const unsigned long long base = 163;
const int INF = 0x3f3f3f3f;
using namespace std;
pair<int, int> p[N];
int main() {
  int n;
  string s;
  cin >> n >> s;
  int tot = 0;
  int l = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'G') {
      if (l == -1) l = i;
    } else if (l != -1) {
      p[++tot] = {l, i - 1};
      l = -1;
    }
  }
  if (s[n - 1] == 'G') p[++tot] = {l, n - 1};
  int ans = 0;
  for (int i = 1; i <= tot - 1; ++i) {
    if (p[i].second + 2 == p[i + 1].first) {
      int MI = p[i + 1].second - p[i].first + 1;
      if (i == tot - 1) MI -= 1;
      ans = max(ans, MI);
    }
    ans = max(ans, p[i].second - p[i].first + 2);
  }
  for (int i = tot; i >= 2; --i) {
    if (p[i].first == p[i - 1].second + 2) {
      int MI = p[i].second - p[i - 1].first + 1;
      if (i == 2) MI -= 1;
      ans = max(ans, MI);
    }
    ans = max(ans, p[i].second - p[i].first + 2);
  }
  if (tot) ans = max(ans, p[tot].second - p[tot].first + 1);
  cout << ans << endl;
  return 0;
}
