#include <bits/stdc++.h>
using namespace std;
struct treep {
  long long x, y, cnt, mins;
  treep* left;
  treep* right;
  treep(int x) {
    this->x = x;
    this->mins = x;
    this->y = rand();
    this->cnt = 1;
    this->left = nullptr;
    this->right = nullptr;
  }
  treep() {}
};
long long cnt(treep* root) {
  if (root != nullptr) return root->cnt;
  return 0;
}
long long mins(treep* root) {
  if (root != nullptr) return root->mins;
  return 1e9 + 113;
}
void upd_cnt(treep* root) {
  if (root != nullptr) root->cnt = cnt(root->left) + cnt(root->right) + 1;
}
void upd_mins(treep* root) {
  if (root != nullptr)
    root->mins = min(min(mins(root->left), mins(root->right)), root->x);
}
void recalc(treep* root) {
  upd_mins(root);
  upd_cnt(root);
}
treep* merge(treep* l, treep* r) {
  recalc(l);
  recalc(r);
  if (l == nullptr) return r;
  if (r == nullptr) return l;
  if (l->y > r->y) {
    l->right = merge(l->right, r);
    recalc(l);
    return l;
  } else {
    r->left = merge(l, r->left);
    recalc(r);
    return r;
  }
}
pair<treep*, treep*> split(treep* root, long long x) {
  recalc(root);
  if (root == nullptr) return {nullptr, nullptr};
  if (cnt(root->left) < x) {
    auto res = split(root->right, x - cnt(root->left) - 1);
    root->right = res.first;
    recalc(root);
    return {root, res.second};
  } else {
    auto res = split(root->left, x);
    root->left = res.second;
    recalc(root);
    return {res.first, root};
  }
}
treep* insert(treep* root, long long value, long long x) {
  auto spl = split(root, x);
  pair<bool, int> d;
  treep* nw = new treep(value);
  auto a = merge(merge(spl.first, nw), spl.second);
  recalc(a);
  return a;
}
treep* del(treep* root, long long l, long long r) {
  auto spl1 = split(root, l);
  auto spl2 = split(spl1.second, r - l);
  auto a = merge(spl1.first, spl2.second);
  recalc(a);
  return a;
}
treep* sdv(treep* root, int q) {
  auto spl = split(root, q);
  auto a = merge(spl.second, spl.first);
  recalc(a);
  return a;
}
void output(treep* t) {
  if (!t) return;
  recalc(t);
  output(t->left);
  cout << t->x << " ";
  output(t->right);
}
long long minsearch(treep* root) {
  if (root == nullptr) return 0;
  if (mins(root->left) == root->mins)
    return minsearch(root->left);
  else if (root->x == root->mins)
    return cnt(root->left);
  else
    return minsearch(root->right) + cnt(root->left) + 1;
}
int main() {
  srand(1);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.setf(ios::fixed);
  cout.precision(0);
  int n;
  cin >> n;
  treep* sde = nullptr;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sde = insert(sde, a, i);
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long t = minsearch(sde);
    sum += t + 1;
    sde = sdv(sde, t);
    sde = del(sde, 0, 1);
  }
  cout << sum;
}
