#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, num[maxn * 2][2];
char a[maxn];
int main() {
  scanf("%d", &n);
  scanf("%s", a + 1);
  int sum = 0;
  for (int i = -n; i <= n; ++i) num[i + maxn][0] = num[maxn + i][1] = -1;
  num[maxn][0] = num[maxn][1] = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == '1')
      sum++;
    else
      sum--;
    if (num[sum + maxn][0] == -1)
      num[sum + maxn][0] = i;
    else
      num[sum + maxn][1] = i;
  }
  int ans = 0;
  for (int i = -n; i <= n; ++i) {
    if (num[i + maxn][0] != -1 && num[i + maxn][1] != -1)
      ans = max(ans, num[i + maxn][1] - num[i + maxn][0]);
  }
  printf("%d\n", ans);
  return 0;
}
