#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
using namespace std;
const int maxn = 100005;
int a[maxn];
set<int> s[maxn];
set<int>::iterator k;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s[a[i]].insert(i);
  }
  sort(a + 1, a + 1 + n);
  long long ans = n, mid = 1, t = n;
  for (int i = 1; i <= n; i++) {
    k = s[a[i]].lower_bound(mid);
    if (k == s[a[i]].end()) {
      ans += t;
      mid = 1;
      k = s[a[i]].lower_bound(mid);
    }
    mid = *k;
    s[a[i]].erase(k);
    t--;
  }
  cout << ans << endl;
}
