#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 6;
long long n, a[maxn], st[(maxn) << 3];
set<long long> myset;
set<long long> v[maxn];
long long qL, qR;
void getInput() {
  cin >> n;
  for (long long i = 0; i < n; i++)
    cin >> a[i], myset.insert(a[i]), v[a[i]].insert(i);
}
long long genSegTree(long long s, long long e, long long i) {
  if (s == e) {
    st[i] = 1;
    return st[i];
  }
  long long m = (s + e) >> 1;
  return (st[i] = (genSegTree(s, m, (i << 1) + 1) +
                   genSegTree(m + 1, e, (i << 1) + 2)));
}
long long getSum(long long s, long long e, long long i) {
  if (qL > e) return 0;
  if (qR < s) return 0;
  if (qL <= s && e <= qR) return st[i];
  long long m = (s + e) >> 1;
  return (getSum(s, m, (i << 1) + 1) + getSum(m + 1, e, (i << 1) + 2));
}
long long update(long long s, long long e, long long i) {
  if (qL > e) return st[i];
  if (qR < s) return st[i];
  if (qL <= s && e <= qR) return (st[i] = 0);
  long long m = (s + e) >> 1;
  return (st[i] =
              (update(s, m, (i << 1) + 1) + update(m + 1, e, (i << 1) + 2)));
}
void solve() {
  genSegTree(0, n - 1, 0);
  long long curPos = 0;
  long long ans = 0;
  for (auto i : myset) {
    while (v[i].size()) {
      auto itr = v[i].lower_bound(curPos);
      if (itr == v[i].end()) {
        qL = curPos, qR = n - 1;
        ans += getSum(0, n - 1, 0);
        curPos = 0;
        continue;
      } else {
        qL = curPos, qR = *itr;
        ans += getSum(0, n - 1, 0);
        qL = curPos = qR;
        update(0, n - 1, 0);
      }
      v[i].erase(itr);
    }
  }
  cout << ans << endl;
}
signed main() {
  long long t = 1;
  while (t--) getInput(), solve();
  return 0;
}
