#include <bits/stdc++.h>
using namespace std;
const int eps = 1e5 + 5;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
char pre[eps];
int arr[eps];
map<int, int> mp;
int main() {
  int n;
  while (~scanf("%d%s", &n, pre)) {
    for (int i = 0; i < n; i++) {
      if (pre[i] == '1')
        arr[i + 1] = 1;
      else
        arr[i + 1] = -1;
    }
    mp.clear();
    int sum = 0, ans = 0;
    int sign = 1;
    for (int i = 1; i <= n; i++) {
      sum += arr[i];
      if (sum == 0) {
        ans = i;
      } else if (mp[sum]) {
        ans = max(ans, i - mp[sum]);
      } else {
        mp[sum] = i;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
