#include <bits/stdc++.h>
using namespace std;
int tr[100001];
int sum(int ind) {
  int sum = 0;
  ind = ind + 1;
  while (ind) {
    sum += tr[ind];
    ind -= ind & (-ind);
  }
  return sum;
}
void update(int ind, int val) {
  ++ind;
  while (ind <= 100000) {
    tr[ind] += val;
    ind += ind & (-ind);
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  set<int> ind[100001];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ind[a[i]].emplace(i);
  }
  long long ans = 1;
  int pos = 0;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    int next;
    if (i > 0 && a[i] == a[i - 1]) {
      next = (ind[a[i]].upper_bound(pos) == ind[a[i]].end())
                 ? *(ind[a[i]].begin())
                 : *(ind[a[i]].upper_bound(pos));
    } else {
      next = (ind[a[i]].lower_bound(pos) == ind[a[i]].end())
                 ? *(ind[a[i]].begin())
                 : *(ind[a[i]].lower_bound(pos));
    }
    int rn = next - sum(next);
    int rp = pos - sum(pos);
    ans += (rn >= rp) ? (long long)(rn - rp) : (long long)(n - i - rp + rn + 1);
    if (i) update(pos, 1);
    pos = next;
  }
  cout << ans << "\n";
}
