#include <bits/stdc++.h>
using namespace std;
struct rr {
  int r;
  int p;
} aa[100005];
char a[100005];
bool cmp(rr x, rr y) {
  if (x.r == y.r)
    return x.p < y.p;
  else
    return x.r < y.r;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  cin >> a;
  aa[0].r = 0;
  aa[0].p = 0;
  int maxx = 0, cnt, temp, s;
  for (int i = 0; i < n; i++) {
    if (a[i] == '0')
      aa[i + 1].r = aa[i].r - 1;
    else
      aa[i + 1].r = aa[i].r + 1;
    aa[i + 1].p = i + 1;
  }
  sort(aa, aa + n + 1, cmp);
  temp = aa[0].r;
  s = aa[0].p;
  for (int i = 0; i <= n; i++) {
    if (aa[i].r == temp) {
      cnt = aa[i].p - s;
      maxx = max(maxx, cnt);
    } else {
      temp = aa[i].r;
      s = aa[i].p;
    }
  }
  cout << maxx << endl;
}
