#include <bits/stdc++.h>
using namespace std;
long long int n, a[100001], b[200002], c[200002];
string s;
int main() {
  cin >> n;
  cin >> s;
  long long int z = 0, o = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '0') {
      z++;
    } else
      o++;
    a[i] = o - z;
  }
  for (long long int i = 0; i <= (2 * n + 1); i++) {
    b[i] = -1;
    c[i] = -1;
  }
  long long int k = 2 * n + 1;
  b[k / 2] = 0;
  c[k / 2] = 0;
  for (long long int i = 0; i < n; i++) {
    if (b[a[i] + n] == -1)
      b[a[i] + n] = c[a[i] + n] = i + 1;
    else
      c[a[i] + n] = i + 1;
  }
  long long int ans = -1;
  for (long long int i = 0; i < k; i++) {
    if (c[i] - b[i] > ans) ans = c[i] - b[i];
  }
  cout << ans << endl;
  return 0;
}
