#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000 + 7;
long long modd(long long a, long long b) {
  long long c = a % b;
  return (c < 0) ? c + b : c;
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt1[n], cnt0[n], cnt00 = 0, cnt11 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      cnt11++;
    else
      cnt00++;
    cnt1[i] = cnt11;
    cnt0[i] = cnt00;
  }
  map<int, int> m;
  int len = 0;
  for (int i = 0; i < n; i++) {
    int x = cnt1[i] - cnt0[i];
    if (x == 0)
      len = max(len, i + 1);
    else {
      if (m[x] != 0)
        len = max(len, i + 1 - m[x]);
      else
        m[x] = i + 1;
    }
  }
  cout << len;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
