#include <bits/stdc++.h>
using namespace std;
vector<long long> st, en;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  string s;
  cin >> n >> s;
  long long cntg = 0, cnts = 0, i = 0, maxg = 0;
  while (i < n) {
    if (s[i] == 'G') {
      st.push_back(i);
      while (i < n && s[i] == 'G') i++;
      en.push_back(i - 1);
      cntg += (en.back() - st.back() + 1);
      maxg = max(maxg, en.back() - st.back() + 1);
    } else {
      cnts++;
      i++;
    }
  }
  long long len1, len2;
  for (long long i = 0; i < (long long)st.size() - 1; i++) {
    len1 = en[i] - st[i] + 1;
    len2 = en[i + 1] - st[i + 1] + 1;
    if (st[i + 1] == en[i] + 2) {
      cntg -= (len1 + len2);
      if (cntg > 0)
        maxg = max(maxg, len1 + len2 + 1);
      else
        maxg = max(maxg, len1 + len2);
      cntg += (len1 + len2);
    } else {
      cntg -= len1;
      if (cntg > 0) maxg = max(maxg, len1 + 1);
      cntg += len1;
    }
  }
  if ((long long)st.size() > 0)
    len1 = en[(long long)st.size() - 1] - st[(long long)st.size() - 1] + 1;
  else
    len1 = 0;
  cntg -= len1;
  if (cntg > 0) maxg = max(maxg, len1 + 1);
  cntg += len1;
  cout << maxg << '\n';
  return 0;
}
