#include <bits/stdc++.h>

using namespace std;

const int maxn = static_cast<const int>(5e6 + 10);
int n;
int tree[maxn];
struct node
{
    int a, b;
} a[maxn];

int lb(int x)
{
    return x & (-x);
}

int read(int x)
{
    int tot = 0;
    for (int i = x; i; i -= lb(i))
        tot += tree[i];
    return tot;
}

void add(int num, int x)
{
    for (int i = x; i <= n; i += lb(i))
        tree[i] += num;
}

bool cmp(struct node &x, struct node &y)
{
    return x.a > y.a;
}

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(0);
    cout.tie(0);
    cin >> n;
    memset(tree, 0, sizeof(tree));
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].a;
        a[i].b = read(n) - read(a[i].a);
        add(1, a[i].a);
    }
    sort(a + 1, a + 1 + n, cmp);
    int pos;
    for (pos = 1; pos <= n; ++pos)
        if (a[pos].b != 0)
            break;
    cout << n - (pos - 1) << endl;
    return 0;
}