#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<int, int> mp;
  int dp[100006];
  int ans = 0;
  dp[0] = (s[0] == '0') ? (-1) : (1);
  mp[dp[0]] = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == '1') {
      dp[i] = 1 + dp[i - 1];
      if (dp[i] == 0) {
        ans = max(ans, i + 1);
      } else if (mp[dp[i]] != 0) {
        ans = max(ans, i + 1 - mp[dp[i]]);
      } else {
        mp[dp[i]] = i + 1;
      }
    } else {
      dp[i] = dp[i - 1] - 1;
      if (dp[i] == 0) {
        ans = max(ans, i + 1);
      } else if (mp[dp[i]] != 0) {
        ans = max(ans, i + 1 - mp[dp[i]]);
      } else {
        mp[dp[i]] = i + 1;
      }
    }
  }
  cout << ans << "\n";
}
