#include <bits/stdc++.h>
using namespace std;
class Point {
 public:
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator+(Point p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
  Point operator*(double a) { return Point(x * a, y * a); }
  Point operator/(double a) { return Point(x / a, y / a); }
  double absv() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
  bool operator==(const Point &p) const {
    return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
  }
};
struct Segment {
  Point p1, p2;
};
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
bool parareru(Point a, Point b, Point c, Point d) {
  return abs(cross(a - b, d - c)) < (1e-10);
}
double distance_ls_p(Point a, Point b, Point c) {
  if (dot(b - a, c - a) < (1e-10)) return (c - a).absv();
  if (dot(a - b, c - b) < (1e-10)) return (c - b).absv();
  return abs(cross(b - a, c - a)) / (b - a).absv();
}
bool is_intersected_ls(Segment a, Segment b) {
  if (a.p1 == b.p1 || a.p2 == b.p1 || a.p1 == b.p2 || a.p2 == b.p2)
    return false;
  if (parareru((a.p2), (a.p1), (a.p1), (b.p2)) &&
      parareru((a.p2), (a.p1), (a.p1), (b.p1))) {
    if (dot(a.p1 - b.p1, a.p1 - b.p2) < (1e-10)) return true;
    if (dot(a.p2 - b.p1, a.p2 - b.p2) < (1e-10)) return true;
    if (dot(a.p1 - b.p1, a.p2 - b.p1) < (1e-10)) return true;
    if (dot(a.p1 - b.p2, a.p2 - b.p2) < (1e-10)) return true;
    return false;
  } else
    return (cross(a.p2 - a.p1, b.p1 - a.p1) * cross(a.p2 - a.p1, b.p2 - a.p1) <
            (1e-10)) &&
           (cross(b.p2 - b.p1, a.p1 - b.p1) * cross(b.p2 - b.p1, a.p2 - b.p1) <
            (1e-10));
}
double segment_dis(Segment a, Segment b) {
  if (is_intersected_ls(a, b)) return 0;
  double r = distance_ls_p(a.p1, a.p2, b.p1);
  r = min(r, distance_ls_p(a.p1, a.p2, b.p2));
  r = min(r, distance_ls_p(b.p1, b.p2, a.p2));
  r = min(r, distance_ls_p(b.p1, b.p2, a.p1));
  return r;
}
Point intersection_ls(Segment a, Segment b) {
  Point ba = b.p2 - b.p1;
  double d1 = abs(cross(ba, a.p1 - b.p1));
  double d2 = abs(cross(ba, a.p2 - b.p1));
  double t = d1 / (d1 + d2);
  return a.p1 + (a.p2 - a.p1) * t;
}
string itos(long long i) {
  ostringstream s;
  s << i;
  return s.str();
}
long long gcd(long long v, long long b) {
  if (v > b) return gcd(b, v);
  if (v == b) return b;
  if (b % v == 0) return v;
  return gcd(v, b % v);
}
double distans(double x1, double y1, double x2, double y2) {
  double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  return sqrt(rr);
}
long long pr[2000010];
long long inv[2000010];
long long beki(long long wa, long long rr, long long warukazu) {
  if (rr == 0) return 1ll;
  if (rr == 1) return wa % warukazu;
  if (rr % 2 == 1) return (beki(wa, rr - 1, warukazu) * wa) % warukazu;
  long long zx = beki(wa, rr / 2, warukazu);
  return (zx * zx) % warukazu;
}
void gya() {
  pr[0] = 1;
  for (long long i = 1; i < 2000010; i++) {
    pr[i] = (pr[i - 1] * i) % 1000000007;
  }
  for (long long i = 0; i < 2000010; i++)
    inv[i] = beki(pr[i], 1000000007 - 2, 1000000007);
}
long long par[200100], ranks[200100], kosuu[200100];
void shoki(long long n) {
  for (long long i = 0; i < n; i++) {
    par[i] = i;
    ranks[i] = 0;
    kosuu[i] = 1;
  }
}
long long root(long long x) { return par[x] == x ? x : par[x] = root(par[x]); }
bool same(long long x, long long y) { return root(x) == root(y); }
void unite(long long x, long long y) {
  x = root(x);
  y = root(y);
  long long xx = kosuu[x], yy = kosuu[y];
  if (x == y) return;
  if (ranks[x] < ranks[y]) {
    par[x] = y;
    kosuu[y] = yy + xx;
  } else {
    par[y] = x;
    if (ranks[x] == ranks[y]) ranks[x] = ranks[x] + 1;
    kosuu[x] = yy + xx;
  }
  return;
}
long long N = 262144;
pair<long long, pair<long long, long long> > sgt[530000];
pair<long long, pair<long long, long long> > maxis(long long i, long long j) {
  if (i == j)
    return sgt[i];
  else if (i % 2 == 1) {
    pair<long long, pair<long long, long long> > z = maxis(i + 1, j);
    if (sgt[i].first >= z.first)
      return sgt[i];
    else
      return z;
  } else if (j % 2 == 0) {
    pair<long long, pair<long long, long long> > z = maxis(i, j - 1);
    if (sgt[j].first > z.first)
      return sgt[j];
    else
      return z;
  } else
    return maxis(i / 2, j / 2);
}
pair<long long, pair<long long, long long> > sgtmax(long long i, long long j) {
  return maxis(i + N, j + N);
}
void upd(long long x, long long y, long long z) {
  x += N;
  sgt[x].first = y;
  sgt[x].second.first += z;
  x = x / 2;
  while (x != 0) {
    if (sgt[2 * x + 1].first > sgt[2 * x].first) {
      sgt[x] = sgt[2 * x + 1];
    } else
      sgt[x] = sgt[2 * x];
    x = x / 2;
  }
}
long long a[530000];
long long con;
long long sumsx(long long i, long long j) {
  if (i > j) return 0;
  if (i == j)
    return a[i];
  else if (i % 2 == 1)
    return a[i] + sumsx(i + 1, j);
  else if (j % 2 == 0)
    return a[j] + sumsx(i, j - 1);
  else
    return sumsx(i / 2, j / 2);
}
void updsum(long long x, long long y) {
  x += con;
  a[x] = a[x] + y;
  x = x / 2;
  while (x != 0) {
    a[x] = a[2 * x + 1] + a[2 * x];
    x = x / 2;
  }
}
long long sgtsum(long long i, long long j) { return sumsx(i + con, j + con); }
vector<pair<long long, long long> > ve;
signed main() {
  long long n, m;
  cin >> n;
  con = N;
  long long d = 0, cn = 0;
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    if (k == d)
      cn++;
    else {
      if (d != 0) ve.push_back(make_pair(cn, d));
      cn = 1;
      d = k;
    }
  }
  ve.push_back(make_pair(cn, d));
  for (long long i = 0; i < ve.size(); i++) {
    sgt[i + N] = make_pair(ve[i].first, make_pair(ve[i].second, i));
    a[i + N] = 1;
  }
  for (long long i = ve.size(); i < N; i++) {
    sgt[i + N] = make_pair(0, make_pair(0, i));
    a[i + N] = 0;
  }
  for (long long i = con - 1; i > 0; i--) a[i] = a[2 * i] + a[2 * i + 1];
  for (long long i = N - 1; i > 0; i--) {
    if (sgt[2 * i].first >= sgt[2 * i + 1].first)
      sgt[i] = sgt[2 * i];
    else
      sgt[i] = sgt[2 * i + 1];
  }
  long long ans = 0;
  while (n > 0) {
    pair<long long, pair<long long, long long> > z = sgtmax(0, N - 2);
    upd(z.second.second, 0, 0);
    n -= z.first;
    ans++;
    updsum(z.second.second, -1);
    if (sgtsum(0, z.second.second) == 0) continue;
    if (sgtsum(z.second.second, N - 3) == 0) continue;
    long long s3, s4;
    long long si = 0, ue = z.second.second, me;
    while (ue - si > 1) {
      me = (ue + si) / 2;
      if (sgtsum(me, z.second.second))
        si = me;
      else
        ue = me;
    }
    s3 = si;
    si = z.second.second;
    ue = N - 3;
    while (ue - si > 1) {
      me = (ue + si) / 2;
      if (sgtsum(z.second.second, me))
        ue = me;
      else
        si = me;
    }
    s4 = ue;
    if (sgt[N + s3].second.first != sgt[N + s4].second.first) continue;
    long long u = sgt[N + s4].first;
    upd(s3, sgt[N + s3].first + u, 0);
    upd(s4, 0, 0);
    updsum(s4, -1);
  }
  cout << ans << endl;
  return 0;
  return 0;
}
