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