#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
const long long inf = 4611686018427387903;
void read() {}
template <typename Arg, typename... Args>
void read(Arg& arg, Args&... args) {
  cin >> (arg);
  read(args...);
}
void print() {}
template <typename Arg, typename... Args>
void print(Arg arg, Args... args) {
  cout << (arg) << " ";
  print(args...);
}
long long getInt() {
  long long a;
  cin >> a;
  return a;
}
long long popcount(long long a) { return __builtin_popcount(a); }
void run() {
  long long n;
  cin >> n;
  string S;
  cin >> S;
  long long cur = 0;
  v<vector<long long> > pos = {vector<long long>()};
  for (char i : S)
    if (i == 'G')
      cur++;
    else {
      if (cur == 0)
        pos.push_back(vector<long long>());
      else
        pos.back().push_back(cur);
      cur = 0;
    }
  if (cur) pos.back().push_back(cur);
  v<vector<long long> > nxt;
  for (vector<long long> i : pos)
    if (!i.empty()) nxt.push_back(i);
  long long ans = 0;
  for (vector<long long> i : nxt) {
    long long s = 0;
    if (((long long)i.size()) <= 2) {
      if (((long long)nxt.size()) > 1) s++;
      for (long long j : i) s += j;
    } else {
      long long pr = 0;
      for (long long j : i) {
        s = max(s, j + pr + 1);
        pr = j;
      }
    }
    ans = max(ans, s);
  }
  cout << ans;
}
signed main() {
  srand(time(0));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(15);
  run();
  return 0;
}
