#include <bits/stdc++.h>
using namespace std;
vector<bool> v;
map<int, int> mp;
int n;
int main() {
  string s;
  cin >> n >> s;
  int maxi = 0;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    v[i] = s[i] - '0';
  }
  vector<pair<int, int> > c(n);
  vector<int> cu(n);
  if (v[0]) {
    c[0].first = 1;
    c[0].second = 0;
  } else {
    c[0].first = 0;
    c[0].second = 1;
  }
  cu[0] = c[0].first - c[0].second;
  mp[cu[0]] = 0;
  mp[0] = -1;
  for (int i = 1; i < n; i++) {
    if (v[i]) {
      c[i].first = 1 + c[i - 1].first;
      c[i].second = c[i - 1].second;
    } else {
      c[i].first = c[i - 1].first;
      c[i].second = 1 + c[i - 1].second;
    }
    cu[i] = c[i].first - c[i].second;
    if (mp.count(cu[i])) {
      maxi = max(maxi, i - mp[cu[i]]);
    } else
      mp[cu[i]] = i;
  }
  cout << maxi;
}
