#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
string s;
int a, b;
int l;
map<int, int> mp;
int main() {
  a = 0;
  b = 0;
  cin >> n;
  int mx = 0;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      a++;
    else if (s[i] == '0')
      b++;
    if (a == b) {
      mx = i + 1;
    } else {
      if (mp[a - b] == 0)
        mp[a - b] = i + 1;
      else
        mx = max(mx, i + 1 - mp[a - b]);
    }
  }
  cout << mx << endl;
  return 0;
}
