#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, cnts = 0, cntg = 0;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v;
  int flags = 0, flagg = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'G') {
      cnts++;
      if (cntg) {
        v.push_back(-1 * cntg);
        cntg = 0;
      }
      flags = 1;
    } else {
      cntg++;
      if (cnts) {
        v.push_back(cnts);
        cnts = 0;
      }
      flagg = 1;
    }
  }
  if (cnts)
    v.push_back(cnts);
  else if (cntg)
    v.push_back(-1 * cntg);
  if (flagg == 0) {
    cout << n << endl;
    return 0;
  } else if (flags == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long maxm = 0;
  for (long long i = 0; i < v.size(); i++) {
    if (i == 0 && v[i] < 0)
      continue;
    else if (i == v.size() - 1 && v[i] < 0)
      continue;
    else {
      if (v[i] == -1) {
        int flag = 0;
        long long len = 0;
        for (long long j = i + 3; j < v.size(); j++) {
          if (v[j] > 0) {
            flag = 1;
            break;
          }
        }
        for (long long j = i - 3; j >= 0; j--) {
          if (v[j] > 0) {
            flag = 1;
            break;
          }
        }
        if (flag)
          len = v[i + 1] + v[i - 1] + 1;
        else
          len = v[i + 1] + v[i - 1];
        maxm = max(maxm, len);
      } else {
        int flag = 0;
        for (long long j = i + 2; j < v.size(); j++) {
          if (v[j] > 0) {
            flag = 1;
            break;
          }
        }
        for (long long j = i - 2; j >= 0; j--) {
          if (v[j] > 0) {
            flag = 1;
            break;
          }
        }
        if (flag)
          maxm = max(maxm, v[i] + 1);
        else
          maxm = max(maxm, v[i]);
      }
    }
  }
  cout << maxm << endl;
  return 0;
}
