#include <bits/stdc++.h>
using namespace std;
int a[100002];
struct Node {
  int x;
  int pos;
  bool operator<(const Node &b) const {
    if (x != b.x) return x < b.x;
    return pos < b.pos;
  }
};
struct Segment_tree {
  Node node[400005];
  int size;
  void build(int n) {
    n += 2;
    size = 1;
    while (size <= n) size <<= 1;
    memset(node, 0, sizeof(node));
  }
  void updata(int pos) {
    node[pos] = min(node[pos + pos], node[pos + pos + 1]);
  }
  void build(int n, int arr[]) {
    build(n);
    int i;
    for (i = 1; i <= n; i++) {
      node[size + i].x = arr[i];
      node[size + i].pos = i;
    }
    for (i = size - 1; i; i--) {
      updata(i);
    }
  }
  void change(int k) {
    k += size;
    node[k].x = 1e9;
    k >>= 1;
    while (k) {
      updata(k);
      k >>= 1;
    }
  }
  Node query(int l, int r) {
    l += size - 1;
    r += size + 1;
    Node ans = node[l + 1];
    for (; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) {
        ans = min(ans, node[l ^ 1]);
      }
      if (r & 1) {
        ans = min(ans, node[r ^ 1]);
      }
    }
    return ans;
  }
} tree1;
struct tree_arr {
  int c[200005], size;
  tree_arr() { memset(c, 0, sizeof(c)); }
  int lowbit(int x) { return x & (-x); }
  int getsum(int x) {
    int ans = 0;
    while (x) {
      ans += c[x];
      x -= lowbit(x);
    }
    return ans;
  }
  void updata(int n, int x, int k) {
    while (x <= n) {
      c[x] += k;
      x += lowbit(x);
    }
  }
} tree2;
int main() {
  int i, j, n, m, now;
  long long ans;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    tree2.updata(n, i, 1);
  }
  tree1.build(n, a);
  now = 1;
  Node x, y;
  ans = 1;
  for (i = 1; i <= n; i++) {
    if (now == 1) {
      x = tree1.query(1, n);
      ans += tree2.getsum(x.pos) - tree2.getsum(1);
    } else if (now == n) {
      x = tree1.query(1, n);
      ans += tree2.getsum(x.pos);
    } else {
      x = tree1.query(now + 1, n);
      y = tree1.query(1, now - 1);
      if (x.x <= y.x) {
        ans += tree2.getsum(x.pos) - tree2.getsum(now);
      } else {
        ans += tree2.getsum(n) - tree2.getsum(now) + tree2.getsum(y.pos);
        x = y;
      }
    }
    tree2.updata(n, x.pos, -1);
    tree1.change(x.pos);
    now = x.pos;
  }
  printf("%I64d\n", ans);
}
