#include <bits/stdc++.h>
using namespace std;
int setbit(int n, int i, int v) {
  return ((v) ? (n | (1 << i)) : (n & ~(1 << i)));
}
long long gcd(int i, int j) {
  if (j == 0) return i;
  return gcd(j, i % j);
}
bool chk(int n, int i) {
  if ((n >> i) & 1 == 1) return 1;
  return 0;
}
string tostring1(long long n) {
  string res = "";
  while (n) {
    res += ((n % 10) + '0');
    n /= 10;
  }
  reverse(res.begin(), res.end());
  return res;
}
long long todec(string s) {
  long long res = 0;
  long long cnt = 0;
  for (int i = s.length() - 1; i >= 0; i--) {
    res += (s[i] - '0') * pow(10, cnt);
    cnt++;
  }
  return res;
}
int a[100004];
int p[400004];
int main() {
  int n;
  cin >> n;
  memset(a, 0, sizeof a);
  for (int i = 0; i < 400004; i++) p[i] = -200000;
  string s;
  cin >> s;
  int ans = 0;
  int res = 0;
  p[200000] = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ans++;
    } else {
      ans--;
    }
    if (p[ans + 200000] == -200000) p[ans + 200000] = i;
    res = max(res, (i)-p[ans + 200000]);
  }
  cout << res << endl;
}
