#include <bits/stdc++.h>
using namespace std;
int comp(pair<long long, long long> p1, pair<long long, long long>& p2) {
  return p1.first - p1.second > p2.first - p2.second;
}
int gcd(int a, int b) {
  if (a > b) {
    int temp = b;
    b = a;
    a = temp;
  }
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
int a[1005];
map<long long, long long> ma;
vector<multiset<long long>> vvi;
map<int, int> mp;
int main() {
  int n;
  string s;
  cin >> n;
  getline(cin, s);
  getline(cin, s);
  int one = 0, zero = 0;
  int ans = 0;
  mp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i - 1] == '0') {
      zero++;
    } else {
      one++;
    }
    if (mp.count(zero - one)) {
      ans = max(ans, i - mp[zero - one]);
    } else {
      mp[zero - one] = i;
    }
  }
  cout << ans;
  return 0;
}
