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