#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, a[maxn];
set<int> p[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    p[a[i]].insert(i);
  }
  sort(a + 1, a + n + 1);
  long long ans = n;
  int now = 0;
  for (int i = 1; i <= n; i++) {
    set<int>::iterator it = p[a[i]].lower_bound(now);
    if (it == p[a[i]].end()) {
      ans += n - i + 1;
      now = 0;
      it = p[a[i]].lower_bound(now);
    }
    now = *it;
    p[a[i]].erase(it);
  }
  printf("%lld\n", ans);
  return 0;
}
