#include <bits/stdc++.h>
using namespace std;
long long int choose(long long int n, long long int m) {
  long long int ans = 0;
  long long int num = 1;
  long long int den = 1;
  for (long long int i = 0; i < m; i++) {
    num *= (n - i);
    num = num / (i + 1);
  }
  return num;
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
bool sortDes(long long int i, long long int j) { return i > j; }
int main() {
  long long int i, j, k, n, m, t, q, d, x, y;
  string s;
  long long int start, endi;
  cin >> n >> s;
  pair<long long int, long long int> p;
  pair<long long int, pair<long long int, long long int> > mp;
  long long int mbeauty = 0;
  long long int gold = 0;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == 'G') {
      gold++;
    }
  }
  vector<pair<long long int, pair<long long int, long long int> > > ans;
  m = 0, i = 0, k = 0;
  while (i < n) {
    if (s[i] == 'G') {
      m++;
      if (k == 0) {
        start = i;
        k = 1;
      }
    } else {
      if (k == 1) {
        p.first = start;
        p.second = i - 1;
        mp.first = m;
        mp.second = p;
        ans.push_back(mp);
        m = 0;
        k = 0;
      } else {
        ;
      }
    }
    i++;
  }
  if (m > 0 && k == 1) {
    p.first = start;
    p.second = n - 1;
    mp.first = m;
    mp.second = p;
    ans.push_back(mp);
    m = 0, k = 0;
  }
  long long int presentVal;
  if (ans.size() == 1) {
    cout << ans[0].first << endl;
    return 0;
  }
  if (ans.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 0; i < ans.size() - 1; i++) {
    presentVal = ans[i].first;
    if (ans[i + 1].second.first - ans[i].second.second > 2) {
      presentVal++;
      if (presentVal > mbeauty) {
        mbeauty = presentVal;
      }
    } else {
      if (ans.size() != 2) {
        presentVal = ans[i].first + ans[i + 1].first + 1;
      } else {
        presentVal = ans[i].first + ans[i + 1].first;
      }
      if (presentVal > mbeauty) {
        mbeauty = presentVal;
      }
    }
  }
  if (ans.size() == 2) {
    presentVal = ans[ans.size() - 1].first + 1;
    if (presentVal > mbeauty) {
      mbeauty = presentVal;
    }
  } else {
    presentVal = ans[ans.size() - 1].first + 1;
    if (presentVal > mbeauty) {
      mbeauty = presentVal;
    }
  }
  cout << mbeauty << endl;
  return 0;
}
