#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int dp[n + 1];
  long long int ans = 0;
  map<long long int, vector<long long int>> diff;
  dp[0] = 0;
  diff[0].push_back(0);
  for (long long int i = 1; i <= n; i++) {
    if (s[i - 1] == '0')
      dp[i] = dp[i - 1] + 1;
    else
      dp[i] = dp[i - 1] - 1;
    diff[dp[i]].push_back(i);
  }
  for (long long int i = -100001; i <= 100001; i++)
    if (diff[i].size())
      ans = max(ans, diff[i][diff[i].size() - 1] - diff[i][0]);
  cout << ans;
}
