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