#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void fio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void print(long long* a, long long n) {
  long long i;
  for (i = 0; i < (long long)n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
void print2d(long long a[][1000], long long m, long long n) {
  long long i, j;
  for (i = 0; i < (long long)m; i++) {
    for (j = 0; j < (long long)n; j++) {
      cout << setw(2) << a[i][j];
    }
    cout << endl;
  }
}
int32_t main() {
  fio();
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v;
  long long i;
  long long c = 0;
  long long g = 0;
  for (i = 0; i < (long long)n; i++) {
    if (s[i] == 'G')
      c++, g++;
    else {
      v.push_back(c);
      c = 0;
    }
  }
  if (s[n - 1] == 'G') v.push_back(c);
  if (v[0] == n) {
    cout << n;
    return 0;
  }
  long long f = 0;
  for (i = 0; i < (long long)v.size(); i++) {
    if (v[i] != 0) {
      f = 1;
    }
  }
  if (!f) {
    cout << 0;
    return 0;
  }
  long long v1 = *max_element(v.begin(), v.end());
  v.clear();
  long long* a = new long long[n]();
  c = 0;
  for (i = 0; i < (long long)n; i++) {
    if (s[i] == 'G')
      c++;
    else {
      a[i] = c;
      while (i < n && s[i] == 'S') i++;
      i -= 1;
      c = 0;
    }
  }
  for (i = 1; i < (long long)n - 1; i++) {
    if (s[i] == 'S' && s[i - 1] == 'G' && s[i + 1] == 'G') {
      long long cnt = a[i];
      i += 1;
      while (i < n && s[i] == 'G') {
        cnt++;
        i++;
      }
      if (cnt != g) cnt++;
      v.push_back(cnt);
      i -= 1;
    }
  }
  long long v2 = INT_MIN;
  if (v.size() != 0) v2 = *max_element(v.begin(), v.end());
  if (v1 < g) v1++;
  cout << max(v1, v2) << endl;
}
