#include <bits/stdc++.h>
using namespace std;
static const int _ = []() {
  ios::sync_with_stdio(false);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  return 0;
}();
template <class T>
inline vector<T> rv(long long n) {
  vector<T> v(n);
  for (long long i = 0; i < (n); i++) cin >> v[i];
  return v;
}
template <class T>
inline void pv(const vector<T>& v) {
  for (long long i = 0; i < (v.size()); i++) cout << v[i] << " ";
  cout << endl;
}
template <class T>
inline void amax(T& a, const T& b) {
  if (a < b) a = b;
}
template <class T>
inline void amin(T& a, const T& b) {
  if (a > b) a = b;
}
int main(int argc, char** argv) {
  long long n;
  string s;
  cin >> n >> s;
  char last = s[0];
  long long x = 1, g = 0;
  vector<pair<long long, char>> vp;
  for (long long i = (1); i < (n); i++) {
    if (last == s[i]) {
      x++;
    } else {
      vp.push_back({x, last});
      if (last == 'G') g += x;
      x = 1;
      last = s[i];
    }
  }
  vp.push_back({x, last});
  if (last == 'G') g += x;
  long long best = 0;
  for (long long i = 0; i < (vp.size()); i++) {
    if (vp[i].second == 'G')
      amax(best, vp[i].first);
    else {
      if (vp[i].first == 1) {
        long long k = 0;
        if (i > 0) k += vp[i - 1].first;
        if (i + 1 < vp.size()) k += vp[i + 1].first;
        if (g - k > 0) {
          amax(best, k + 1);
        } else {
          amax(best, k);
        }
      } else {
        long long k = 0;
        if (i > 0) amax(k, vp[i - 1].first);
        if (i + 1 < vp.size()) amax(k, vp[i + 1].first);
        if (g - k > 0) {
          amax(best, k + 1);
        } else {
          amax(best, k);
        }
      }
    }
  }
  cout << best << endl;
  return 0;
}
