#include <bits/stdc++.h>
using namespace std;
int n, a[200100], en[200100];
int bit[200100];
inline void add(int pos, int val) {
  while (pos <= n) {
    bit[pos] += val;
    pos += pos & (-pos);
  }
}
inline int sum(int pos) {
  int ret = 0;
  while (pos > 0) {
    ret += bit[pos];
    pos -= pos & (-pos);
  }
  return ret;
}
int sta[200100], ri;
pair<int, int> v[200100 << 2];
inline void up(int o) { v[o] = max(v[(o << 1)], v[((o << 1) | 1)]); }
void build(int o, int l, int r) {
  if (l == r) {
    v[o] = pair<int, int>(en[l] - l + 1, -l);
    return;
  }
  build((o << 1), l, ((l + r) >> 1));
  build(((o << 1) | 1), ((l + r) >> 1) + 1, r);
  up(o);
}
void del(int o, int l, int r, int pos) {
  if (l == r) {
    v[o] = pair<int, int>(0, 0);
    return;
  }
  if (pos <= ((l + r) >> 1))
    del((o << 1), l, ((l + r) >> 1), pos);
  else
    del(((o << 1) | 1), ((l + r) >> 1) + 1, r, pos);
  up(o);
}
void update(int o, int l, int r, int pos) {
  if (l == r) {
    int len = (en[l] - l + 1) - (sum(en[l]) - sum(l - 1));
    v[o] = pair<int, int>(len, -l);
    return;
  }
  if (pos <= ((l + r) >> 1))
    update((o << 1), l, ((l + r) >> 1), pos);
  else
    update(((o << 1) | 1), ((l + r) >> 1) + 1, r, pos);
  up(o);
}
set<int> s;
set<int>::iterator it;
int tmp[200100], sz;
int t2[200100], s2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    s.insert(i);
  }
  a[n + 1] = -1;
  sta[++ri] = 1;
  for (int i = 2; i <= n + 1; ++i) {
    if (a[sta[ri]] != a[i]) {
      while (ri > 0) {
        en[sta[ri]] = i - 1;
        ri--;
      }
    }
    sta[++ri] = i;
  }
  build(1, 1, n);
  int ans = 0;
  while (v[1].first > 0) {
    ++ans;
    int l = -v[1].second, r = en[l];
    it = s.lower_bound(l);
    sz = 0;
    while (it != s.end() && (*it) <= r) {
      tmp[sz++] = (*it);
      it++;
    }
    int L = -1, R = -1;
    it = s.lower_bound(l);
    if (it != s.begin()) {
      --it;
      L = (*it);
    }
    it = s.upper_bound(r);
    if (it != s.end()) R = (*it);
    s2 = 0;
    if (L > 0 && R > 0 && a[L] == a[R]) {
      it = s.lower_bound(L);
      int v = en[R];
      while (1) {
        if (a[(*it)] != a[R]) break;
        t2[s2++] = (*it);
        en[t2[s2 - 1]] = v;
        if (it == s.begin()) break;
        --it;
      }
    }
    for (int i = 0; i < sz; ++i) {
      add(tmp[i], 1);
      del(1, 1, n, tmp[i]);
      s.erase(tmp[i]);
    }
    for (int i = 0; i < s2; ++i) update(1, 1, n, t2[i]);
  }
  printf("%d\n", ans);
  return 0;
}
