#include <bits/stdc++.h>
int n;
std::vector<int> v[100010];
int main(void) {
  int i, j, k, x;
  long long answer = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &k), v[k].push_back(i);
  j = 0;
  k = 1;
  for (i = 1; i <= 100000; ++i) {
    if (v[i].empty()) continue;
    for (int w : v[i])
      if (w < j)
        answer += k + 1, x = w;
      else
        answer += k;
    if (v[i][0] < j)
      ++k, j = x;
    else
      j = v[i][v[i].size() - 1];
  }
  printf("%lld\n", answer);
  return 0;
}
