#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int dp[2000005];
int main() {
  int n;
  int t1, t2;
  while (scanf("%d", &n) == 1) {
    t1 = n;
    t2 = 0;
    scanf("%s", str);
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    dp[t1] = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '0')
        t1++;
      else
        t1--;
      dp[t1] = min(dp[t1], i + 1);
      t2 = max(t2, i + 1 - dp[t1]);
    }
    printf("%d\n", t2);
  }
  return 0;
}
