#include <bits/stdc++.h>
using namespace std;
int n, a, bit[100010];
void update(int x, int val) {
  for (; x <= n; x += x & -x) bit[x] += val;
}
int query(int x) {
  int sum = 0;
  for (; x > 0; x -= x & -x) sum += bit[x];
  return sum;
}
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 100010; i++) {
    bit[i] = 0;
  }
  s.clear();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    s.insert(make_pair(a, i));
    update(i, 1);
  }
  long long ans = 0;
  int st = 0, en, num;
  while (!s.empty()) {
    num = s.begin()->first;
    it = s.lower_bound(make_pair(num, st));
    if (it == s.end() || it->first > num) {
      it = s.begin();
    }
    en = it->second;
    s.erase(it);
    if (en > st) {
      long long hold = (long long)query(en) - (long long)query(st);
      ans += (hold);
      update(en, -1);
      st = en;
    } else {
      long long hold = (long long)query(n) - (long long)query(st);
      ans += (hold);
      hold = (long long)query(en);
      ans += (hold);
      st = en;
      update(en, -1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
