#include <bits/stdc++.h>
using namespace std;
const long long M = 1e5 + 5;
long long BIT[M], n, s;
set<pair<long long, long long> > s1;
void update(long long x, long long delta) {
  for (; x <= n; x += x & -x) BIT[x] += delta;
}
long long query(long long x) {
  long long sum = 0;
  for (; x > 0; x -= x & -x) sum += BIT[x];
  return sum;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0, x; i < n; i++) {
    cin >> x;
    update(i + 1, 1);
    s1.insert({x, i + 1});
  }
  long long lp = 0;
  pair<long long, long long> aa;
  while (s1.size()) {
    aa = *s1.begin();
    aa.second = lp;
    aa = *s1.upper_bound(aa);
    if (aa.first > (*s1.begin()).first) aa = *s1.begin();
    if (aa.second > lp) {
      s += query(aa.second) - query(lp);
    } else {
      s += query(n) - (query(lp - 1) - query(aa.second));
    }
    s1.erase(aa);
    lp = aa.second;
    update(lp, -1);
  }
  cout << s;
}
