#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int i, ans = 0, sum = 0;
  map<long long int, vector<long long int>> m;
  m[0].push_back(-1);
  for (i = 0; i < n; i++) {
    if (s[i] == '1')
      sum++;
    else
      sum--;
    m[sum].push_back(i);
  }
  for (auto i = m.begin(); i != m.end(); i++) {
    if (m[i->first].size() > 1) {
      ans = max(ans, m[i->first][m[i->first].size() - 1] - m[i->first][0]);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
