#include <bits/stdc++.h>
const int N = 100010;
using namespace std;
int n, tr[N], lp[N], cnt = 0, op[N], p = 0;
vector<int> kp[N];
void add(int x) {
  while (x <= n) tr[x]++, x += x & (-x);
}
void del(int x) {
  while (x <= n) tr[x]--, x += x & (-x);
}
int q_(int x) {
  int s = 0;
  while (x) s += tr[x], x -= x & (-x);
  return s;
}
struct M {
  int id, val;
} sum[N];
bool cmp(M a, M b) { return a.val < b.val; }
void unique_() {
  for (int i = 1; i <= n; i++) sum[i].id = i, sum[i].val = lp[i];
  sort(sum + 1, sum + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (i == 1 || sum[i].val != sum[i - 1].val) cnt++;
    lp[sum[i].id] = cnt;
  }
}
int main() {
  scanf("%d", &n);
  long long ans = n;
  for (int i = 1; i <= n; i++) scanf("%d", &lp[i]);
  unique_();
  for (int i = 1; i <= n; i++) kp[lp[i]].push_back(i);
  for (int i = 1; i <= n; i++) add(i);
  for (int i = 1; i <= cnt; i++) {
    int x = kp[i].size(), y;
    if (!x)
      continue;
    else {
      if (kp[i][x - 1] > p)
        y = lower_bound(kp[i].begin(), kp[i].end(), p) - kp[i].begin();
      else
        y = 0;
      for (int j = y; j < x; j++) {
        if (p < kp[i][j])
          ans += q_(kp[i][j] - 1) - q_(p);
        else
          ans += q_(kp[i][j] - 1) + q_(n) - q_(p);
        p = kp[i][j];
        del(kp[i][j]);
      }
      for (int j = 0; j < y; j++) {
        if (p < kp[i][j])
          ans += q_(kp[i][j] - 1) - q_(p);
        else
          ans += q_(kp[i][j] - 1) + q_(n) - q_(p);
        p = kp[i][j];
        del(kp[i][j]);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
