#include <bits/stdc++.h>
using namespace std;
map<int, int> h;
int n;
pair<int, int> a[1000005];
int l[1000005], r[1000005], ne[1000005], b[1000005], bit[1000005];
void upd(int u, int v) {
  for (; u > 0; u -= u & (-u)) bit[u] += v;
}
int get(int u) {
  int r = 0;
  for (; u <= n; u += u & (-u)) r += bit[u];
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first >> a[i].second;
    b[i] = a[i].second;
    h[a[i].first] = 0;
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    a[i].second = lower_bound(b + 1, b + n + 1, a[i].second) - b;
  }
  for (int i = 1; i <= n; ++i) {
    l[i] = get(a[i].second);
    if (i == n || a[i + 1].first > a[i].first) upd(a[i].second, 1);
  }
  for (int i = 1; i <= n; ++i) {
    bit[i] = 0;
    ne[i] = n + 1;
    h[a[i].first] = max(h[a[i].first], a[i].second);
  }
  int j = n;
  long long ret = 0;
  for (int i = n; i >= 1; --i) {
    while (j > i && a[j].first > a[i].first) {
      if (j == n || a[j + 1].first > a[j].first) upd(a[j].second, 1);
      --j;
    }
    r[i] = get(a[i].second + 1);
    int id = ne[a[i].second];
    int cnt = r[i] - r[id] + 1;
    if (id != n + 1 && h[a[id].first] != a[i].second) cnt--;
    ret += (long long)(l[i] + 1) * cnt;
    ne[a[i].second] = i;
  }
  cout << ret;
}
