#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void bolt() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long zeroes[100001];
long long ones[100001];
int32_t main() {
  bolt();
  long long n;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] == '0')
    zeroes[0] = 1;
  else
    ones[0] = 1;
  for (long long i = 1; i < n; i++) {
    if (s[i] == '0') {
      zeroes[i] = zeroes[i - 1] + 1;
      ones[i] = ones[i - 1];
    } else {
      ones[i] = ones[i - 1] + 1;
      zeroes[i] = zeroes[i - 1];
    }
  }
  map<long long, long long> mp;
  mp[zeroes[0] - ones[0]] = 0;
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    long long diff = zeroes[i] - ones[i];
    if (diff == 0) {
      ans = i + 1;
      continue;
    }
    if (mp.find(diff) != mp.end()) {
      ans = max(ans, i - mp[diff]);
    } else {
      mp[diff] = i;
    }
  }
  cout << ans;
  return 0;
}
