#include <bits/stdc++.h>
using namespace std;
const int tam = 100005;
set<long long int> st[tam];
int main() {
  long long int n, x;
  cin >> n;
  vector<long long int> v;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(x);
    st[x].insert(i - 1);
  }
  sort(v.begin(), v.end());
  long long int pos = 0;
  long long int res = n;
  long long int rema = n;
  for (int i = 0; i < n; i++) {
    x = v[i];
    auto it = st[x].lower_bound(pos);
    if (it == st[x].end()) {
      res += rema;
      pos = 0;
      it = it = st[x].lower_bound(pos);
    }
    pos = *it;
    st[x].erase(it);
    rema--;
  }
  cout << res << endl;
  return 0;
}
