#include <bits/stdc++.h>
using namespace std;
char s[200005];
int offset = 100000;
int sum[200005], n;
set<int> st[200005];
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1')
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1] - 1;
  }
  st[0 + offset].insert(0);
  for (int i = 1; i <= n; i++) st[offset + sum[i]].insert(i);
  int ans = 0;
  for (int i = 1; i < 200005; i++) {
    if (st[i].size() < 2) continue;
    int l = *st[i].begin();
    int r = *st[i].rbegin();
    ans = max(ans, r - l);
  }
  printf("%d\n", ans);
  return 0;
}
