#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int b[maxn];
char a[maxn];
int num[2 * maxn];
int main() {
  int n;
  scanf("%d", &n);
  int count0 = 0, count1 = 0;
  memset(num, -1, sizeof(num));
  int len = 0, maxlen = 0;
  scanf("%s", a + 1);
  for (int i = 1; i <= n; i++) {
    if (a[i] == '0')
      count0++;
    else
      count1++;
    b[i] = count1 - count0;
    if (b[i] == 0) {
      if (maxlen < i) maxlen = i;
      continue;
    }
    if (num[b[i] + maxn] == -1)
      num[b[i] + maxn] = i;
    else {
      len = i - num[b[i] + maxn];
      if (maxlen < len) maxlen = len;
    }
  }
  printf("%d\n", maxlen);
  return 0;
}
