using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        int[] A = Enumerable.Range(0, N).Select(v => NextInt()).ToArray();
        Dictionary<int, int> zip = new Dictionary<int, int>();
        int x = 1;
        int[] B = A.ToArray();
        Array.Sort(A);
        for (int i = 0; i < N; i++)
            if (!zip.ContainsKey(A[i])) { zip[A[i]] = x; x++; }
        MinTree MT = new MinTree(N + 1);
        for (int i = 0; i < N; i++)
        {
            int num = MT.Query(0, zip[B[i]]);
            if (num > 0)
            {
                int pos = MT.MLS(num);
                MT.Add(pos, -1);
            }
            MT.Add(zip[B[i]], 1);
        }
        Console.WriteLine(MT.Query(0, N + 1));
    }

    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class MinTree
{
    private List<int> table = new List<int>();
    private static int size = 1;
    private static int high = 1;
    public MinTree(int n, int k = 0)
    {
        while (size < n) size *= 2;
        high = (int)Math.Log(size, 2);
        for (int i = 0; i < 2 * size - 1; i++) table.Add(k);
    }
    public void Add(int x, int v)
    {
        x += size - 1;
        table[x] += v;
        table[x] = Math.Max(0, table[x]);
        while (x != 0)
        {
            x = (x % 2 == 0 ? x / 2 - 1 : x / 2);
            table[x] = table[x * 2 + 1] + table[x * 2 + 2];
        }
    }
    public int MLS(int k)
    {
        if (table.First() == 0) return -1;
        int index = 0;
        for (int y = 0; y < high; y++)
        {
            int left = index * 2 + 1;
            int right = index * 2 + 2;
            if (table[left] >= k) index = left;
            else { k -= table[left]; index = right; }
        }
        return index - size + 1;
    }
    public int Query(int a, int b, int x = 0, int l = 0, int r = 0)
    {
        if (r <= l) r = size;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return table[x];
        int left = Query(a, b, x * 2 + 1, l, (r + l) / 2);
        int right = Query(a, b, x * 2 + 2, (r + l) / 2, r);
        return left + right;
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 27472