#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cin >> a[i];
}
void print_vec(vector<long long> &v) {
  for (auto i : v) cout << i << " ";
  cout << endl;
}
void print_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << endl;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return a.second < b.second;
}
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
bool sortinrevbysec(const pair<long long, long long> &a,
                    const pair<long long, long long> &b) {
  return (a.second > b.second);
}
template <typename... T>
void input(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void print(T &&...args) {
  ((cout << args << endl), ...);
}
template <typename... T>
void deb(T &&...args) {
  cout << "~~ ";
  ((cout << args << " "), ...);
  cout << endl;
}
void stand8th() {
  long long n;
  input(n);
  string s;
  input(s);
  long long a[n + 1];
  long long b[n + 1];
  a[0] = 0;
  b[0] = 0;
  long long one = 0;
  long long zero = 0;
  for (long long i = 0; i < n; i += 1) {
    if (s[i] == '1')
      one++;
    else {
      zero++;
    }
    a[i + 1] = one;
    b[i + 1] = zero;
  }
  long long c[n + 1];
  for (long long i = 0; i < n + 1; i += 1) {
    c[i] = a[i] - b[i];
  }
  map<long long, long long> mpp, mp1;
  for (long long i = 0; i < n + 1; i += 1) {
    mpp[c[i]] = i;
  }
  for (long long i = n; i >= 0; i--) {
    mp1[c[i]] = i;
  }
  long long ans = -1;
  for (auto vbn : mpp) {
    ans = max(ans, abs(vbn.second - mp1[vbn.first]));
  }
  print(ans);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tin = 1;
  while (tin--) {
    stand8th();
  }
  return 0;
}
