#include <bits/stdc++.h>
using namespace std;
const int base = 100003;
const long long MM = 1ll * 1000000007 * 1000000007;
string s;
int cnt1[200005], cnt0[200005], baln[200005], last[200005], last1[200005];
void Solve() {
  int n;
  cin >> n >> s;
  s = " " + s;
  int maxx = 0;
  for (int i = 1; i <= n; i++)
    if (s[i] == '0')
      cnt0[i] = cnt0[i - 1] + 1, cnt1[i] = cnt1[i - 1];
    else
      cnt1[i] = cnt1[i - 1] + 1, cnt0[i] = cnt0[i - 1];
  for (int i = 1; i <= n; ++i) baln[i] = cnt1[i] - cnt0[i];
  for (int i = 1; i <= n; ++i)
    if (baln[i] == 0) maxx = max(maxx, i);
  for (int i = 1; i <= n; ++i) {
    if (baln[i] >= 0) {
      if (last[baln[i]] == 0)
        last[baln[i]] = i;
      else
        maxx = max(maxx, i - last[baln[i]]);
    } else {
      if (last1[-baln[i]] == 0)
        last1[-baln[i]] = i;
      else
        maxx = max(maxx, i - last1[-baln[i]]);
    }
  }
  cout << maxx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  while (test--) Solve();
}
