#include <bits/stdc++.h>
using namespace std;
long long MOD = pow(10, 9) + 7;
long long INF = 1ll << 60;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[n + 1];
  for (long long i = 1; i < 1 + n; i++) a[i] = s[i - 1] - '0';
  long long in[2 * n + 10];
  for (long long i = 0; i < 2 * n + 10; i++) in[i] = INF;
  long long ans = -1, c = 0;
  a[0] = 0;
  for (long long i = 0; i < n + 1; i++) {
    if (a[i] == 1) {
      c++;
    } else
      c--;
    in[c + n + 5] = min(in[c + n + 5], i);
    ans = max(ans, i - in[c + n + 5]);
  }
  cout << ans << endl;
}
