#include <bits/stdc++.h>
using namespace std;
int zeros[100001];
int ones[100001];
int main(void) {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  string second;
  cin >> second;
  if (second[0] == '0') {
    zeros[0] = 1;
    ones[0] = 0;
  } else {
    ones[0] = 1;
    zeros[0] = 0;
  }
  int g_len = 0;
  int diff[n];
  map<int, int> indices;
  diff[0] = ones[0] - zeros[0];
  indices.insert({diff[0], 0});
  for (int i = 1; i < n; i++) {
    int curr_len = 0;
    if (second[i] == '1') {
      ones[i] = ones[i - 1] + 1;
      zeros[i] = zeros[i - 1];
    } else {
      ones[i] = ones[i - 1];
      zeros[i] = zeros[i - 1] + 1;
    }
    diff[i] = ones[i] - zeros[i];
    if (diff[i] == 0) {
      g_len = max(g_len, i + 1);
    } else if (indices.find(diff[i]) != indices.end()) {
      curr_len = i - indices[diff[i]];
    }
    indices.insert({diff[i], i});
    g_len = max(g_len, curr_len);
  }
  cout << g_len << "\n";
}
