#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
char s[maxn];
int a[maxn];
map<int, int> m;
int main() {
  int n;
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      a[i] = -1;
    else
      a[i] = 1;
  }
  int ans = 0, sum = 0;
  m[0] = 1;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (m[sum])
      ans = max(ans, i - m[sum] + 2);
    else
      m[sum] = i + 2;
  }
  cout << ans << endl;
}
