#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
void print_map(map<T, S>& m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << " -> " << i->second << endl;
  }
}
int main() {
  uint32_t n;
  cin >> n;
  string s;
  cin >> s;
  map<int32_t, int32_t> smallest_index_with_same_val;
  int32_t prefix_sum = 0;
  prefix_sum += s[0] == '1' ? 1 : -1;
  smallest_index_with_same_val[prefix_sum] = 0;
  smallest_index_with_same_val[0] = -1;
  uint32_t best = 0;
  for (uint32_t i = 1; i < n; i++) {
    prefix_sum += s[i] == '1' ? 1 : -1;
    if (smallest_index_with_same_val.count(prefix_sum) > 0) {
      best = max<uint32_t>(best, i - smallest_index_with_same_val[prefix_sum]);
    } else {
      smallest_index_with_same_val[prefix_sum] = i;
    }
  }
  cout << best << endl;
  return 0;
}
