//  [javascript]
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var SET=(function(){
  var t,u,ts;
  function f(){return new mySet();}
  function mySet(){
    t=this.tree=[{Parent:-1,isBlack:1}];
    this.root=0;
    u=this.unused=[];
    this.size=0;
    ts=this;
  }
  mySet.prototype.xor=function(x){
    var n=ts.root;
    while(t[n].leftChild!==undefined){
      if(t[n].value===x)return this.deleteAddr(n);
      if(t[n].value<x)n=t[n].rightChild;
      else n=t[n].leftChild;
    }
    add(x,n);
  }
  mySet.prototype.add=function(x){
    var n = ts.root;
    while(t[n].leftChild!==undefined){
      if(t[n].value===x)return false;
      if(t[n].value<x)n=t[n].rightChild;
      else n=t[n].leftChild;
    }
    add(x,n);
    return true;
  }
  function add(x,n){
    var m=n,p=t[m].Parent;
    while(p!==-1){
      if(t[p].leftChild===m)t[p].lChildSize++;
      m=p,p=t[p].Parent;
    }
    treeAdd(n,x);
  }
  function treeAdd(n,x){
    ts.size++;
    t[n].value=x;
    t[n].lChildSize=t[n].isBlack=0;
    createChild(n);
    var p=t[n].Parent;
    if(p===-1){
      //根の処理
      t[n].isBlack=1;
    }else if(t[p].isBlack===0){
      //親が赤の場合の処理
      rotate(n,p);
    }
  }
  function createChild(n){
    var l,r;
    if(u.length){
      l=u.pop();
      t[l].Parent=n;
      if(u.length){
        r=u.pop();
        t[r].Parent=n;
      }else{
        r=t.length;
        t.push({Parent:n,isBlack:1});
      }
    }else{
      l=t.length, r=l+1;
      t.push({Parent:n,isBlack:1},{Parent:n,isBlack:1});
    }
    t[n].leftChild=l;
    t[n].rightChild=r;
  }
  function rotate(n,p){
    var pp=t[p].Parent,p3=t[pp].Parent;
    if(t[n].value<t[p].value){
      if(t[p].value<t[pp].value){
        t[p].Parent=p3;
        t[pp].Parent=p;
        t[pp].leftChild=t[p].rightChild;
        t[p].rightChild=t[t[pp].leftChild].Parent=pp;
        t[pp].lChildSize-=t[p].lChildSize+1;
        t[n].isBlack=1,t[p].isBlack=0;
        if(p3===-1){t[p].isBlack=1;ts.root=p;}else{
          if(t[p].value<t[p3].value)t[p3].leftChild=p;else t[p3].rightChild=p;
          if(t[p3].isBlack===0)rotate(p,p3);
        }
      }else{
        t[pp].rightChild=t[p].Parent=n;
        t[p].leftChild=t[n].rightChild;
        t[p].lChildSize-=t[n].lChildSize+1;
        t[n].rightChild=t[t[p].leftChild].Parent=p;
        t[n].Parent=pp;
        rotate(p,n);
      }
    }else{
      if(t[p].value<t[pp].value){
        t[pp].leftChild=t[p].Parent=n;
        t[p].rightChild=t[n].leftChild;
        t[n].lChildSize+=t[p].lChildSize+1;
        t[n].leftChild=t[t[p].rightChild].Parent=p;
        t[n].Parent=pp;
        rotate(p,n);
      }else{
        t[p].Parent=p3;
        t[pp].Parent=p;
        t[pp].rightChild=t[p].leftChild;
        t[p].leftChild=t[t[pp].rightChild].Parent=pp;
        t[p].lChildSize+=t[pp].lChildSize+1;
        t[n].isBlack=1,t[p].isBlack=0;
        if(p3===-1){t[p].isBlack=1;ts.root=p;}else{
          if(t[p].value<t[p3].value)t[p3].leftChild=p;else t[p3].rightChild=p;
          if(t[p3].isBlack===0)rotate(p,p3);
        }
      }
    }
  }
  mySet.prototype.has=function(x){
    var n=ts.root;
    while(t[n].leftChild!==undefined){
      if(t[n].value===x)return n;
      if(t[n].value<x)n=t[n].rightChild;
      else n=t[n].leftChild;
    }
    return -1;
  }
  mySet.prototype.delete=function(x){
    var n=this.has(x);
    if(n===-1)return false;
    this.deleteAddr(n);
    return true;
  }
  mySet.prototype.deleteAddr=function(n){
    //削除の処理
    var l=t[n].leftChild,r=t[n].rightChild,p=t[n].Parent;
    ts.size--;
    lChildSizeUpdate(n);
    if(t[l].leftChild===undefined){
      if(t[r].isBlack===0){
        t[n].value=t[r].value;
        t[n].rightChild=t[r].rightChild;
        t[t[r].rightChild].Parent=n;
        Unused(r,t[r].leftChild);
        return;
      }
      //子が無い
      var b=t[n].isBlack;
      t[n]={Parent:p,isBlack:1};
      Unused(l,r);
      if(b&&p!==-1){
        if(t[p].leftChild===n)leftShortage(p);
        else rightShortage(p);
      }
      return;
    }
    //交換ノード探索
    var c=l;
    t[n].lChildSize--;
    while(t[t[c].rightChild].leftChild!==undefined)c=t[c].rightChild;
    var b=t[c].isBlack,cl=t[c].leftChild,cp=t[c].Parent,bl=t[cl].isBlack;
    t[n].value=t[c].value;
    if(cp===n)t[n].leftChild=cl;
    else t[cp].rightChild=cl;
    t[cl].Parent=cp;
    Unused(c,t[c].rightChild);
    //交換ノード赤
    if(b===0)return;
    //交換ノード黒左子ノード赤
    if(bl===0){t[cl].isBlack=1;return;}
    //交換ノード黒左子ノード黒
    if(cp===n)leftShortage(n);
    else rightShortage(cp);
  }
  function Unused(a,b){
    u.push(a,b);
    t[a]={isBlack:1},t[b]={isBlack:1};
  }
  function lChildSizeUpdate(n){
    var p=t[n].Parent;
    while(p!==-1){
      if(t[p].leftChild===n)t[p].lChildSize--;
      n=p,p=t[n].Parent;
    }
  }
  function leftShortage(n){
    var r=t[n].rightChild,rl=t[r].leftChild,rr=t[r].rightChild;
    if(t[r].isBlack===0){
      t[r].isBlack=1,t[n].isBlack=0;
      changeChild(n,r);
      t[rl].Parent=t[r].leftChild=n;
      t[n].Parent=r,t[n].rightChild=rl;
      t[r].lChildSize+=t[n].lChildSize+1;
      leftShortage(n);
    }else if(t[rr].isBlack===0){
      t[r].isBlack=t[n].isBlack;
      t[n].isBlack=t[rr].isBlack=1;
      changeChild(n,r);
      t[rl].Parent=t[r].leftChild=n;
      t[n].Parent=r,t[n].rightChild=rl;
      t[r].lChildSize+=t[n].lChildSize+1;
    }else if(t[rl].isBlack===0){
      var rll=t[rl].leftChild,rlr=t[rl].rightChild;
      t[rl].isBlack=t[n].isBlack;
      t[n].isBlack=1;
      changeChild(n,rl);
      t[rll].Parent=t[rl].leftChild=n;
      t[n].rightChild=rll,t[n].Parent=rl;
      t[rlr].Parent=t[rl].rightChild=r;
      t[r].Parent=rl,t[r].leftChild=rlr;
      t[r].lChildSize-=t[rl].lChildSize+1;
      t[rl].lChildSize+=t[n].lChildSize+1;
    }else{
      var b=t[n].isBlack,p=t[n].Parent;
      t[n].isBlack=1,t[r].isBlack=0;
      if(b&&p!==-1){
        if(t[p].leftChild===n)leftShortage(p);
        else rightShortage(p);
      }
    }
  }
  function rightShortage(n){
    var l=t[n].leftChild,ll=t[l].leftChild,lr=t[l].rightChild;
    if(t[l].isBlack===0){
      t[l].isBlack=1,t[n].isBlack=0;
      changeChild(n,l);
      t[lr].Parent=t[l].rightChild=n;
      t[n].Parent=l,t[n].leftChild=lr;
      t[n].lChildSize-=t[l].lChildSize+1;
      rightShortage(n);
    }else if(t[ll].isBlack===0){
      t[l].isBlack=t[n].isBlack;
      t[n].isBlack=t[ll].isBlack=1;
      changeChild(n,l);
      t[lr].Parent=t[l].rightChild=n;
      t[n].Parent=l,t[n].leftChild=lr;
      t[n].lChildSize-=t[l].lChildSize+1;
    }else if(t[lr].isBlack===0){
      var lrl=t[lr].leftChild,lrr=t[lr].rightChild;
      t[lr].isBlack=t[n].isBlack;
      t[n].isBlack=1;
      changeChild(n,lr);
      t[lrr].Parent=t[lr].rightChild=n;
      t[n].leftChild=lrr,t[n].Parent=lr;
      t[lrl].Parent=t[lr].leftChild=l;
      t[l].Parent=lr,t[l].rightChild=lrl;
      t[lr].lChildSize+=t[l].lChildSize+1;
      t[n].lChildSize-=t[lr].lChildSize+1;
    }else{
      var b=t[n].isBlack,p=t[n].Parent;
      t[n].isBlack=1,t[l].isBlack=0;
      if(b&&p!==-1){
        if(t[p].leftChild===n)leftShortage(p);
        else rightShortage(p);
      }
    }
  }
  function changeChild(b,a){
    var p=t[b].Parent;
    t[a].Parent=p;
    if(p===-1){t[a].isBlack=1;ts.root=a;return;}
    if(t[p].leftChild===b)t[p].leftChild=a;
    else t[p].rightChild=a;
  }
  mySet.prototype.get=function(i){
    if(ts.size<=i)return;
    return t[ts.getAddr(i)].value;
  }
  mySet.prototype.getAddr=function(i){
    var r=ts.root,c=t[r].lChildSize;
    while(c!==i){
      if(c<i){
        i-=1+c;
        r=t[r].rightChild;
      }else{
        r=t[r].leftChild;
      }
      c=t[r].lChildSize;
    };
    return r;
  }
  mySet.prototype.lower_bound=function(v){
    var r=ts.root,s=0;
    while(t[r].leftChild!==undefined){
      if(t[r].value===v)return s+t[r].lChildSize;
      if(v<t[r].value){
        r=t[r].leftChild;
      }else{
        s+=t[r].lChildSize+1;
        r=t[r].rightChild;
      }
    }
    return s;
  }
  mySet.prototype.upper_bound=function(v){
    var r=ts.root,s=0;
    while(t[r].leftChild!==undefined){
      if(v<t[r].value){
        r=t[r].leftChild;
      }else{
        s+=t[r].lChildSize+1;
        r=t[r].rightChild;
      }
    }
    return s;
  }
  mySet.prototype.Array=function(){
    var ans=[];
    dfs(this.root);
    return ans;
    function dfs(n){
      if(t[n].leftChild===undefined)return;
      dfs(t[n].leftChild);
      ans.push(t[n].value);
      dfs(t[n].rightChild);
    }
  }
  return f;
})();

console.log(main());
function main(){
  var n = o.a();
  var a = o.r(n);
  var set = SET();
  set.add(-1);
  var map = new Map();
  map.set(-1,1);
  for(var q = 0; q < n; q++){
    var t = set.lower_bound(a[q]);
    if(t){
      var u = set.get(t-1);
      var x = map.get(u);
      map.set(u,x-1);
      if(x === 1)set.delete(u);
    }
    set.add(a[q]);
    var y = map.get(a[q]);
    if(y)map.set(a[q],y+1);
    else map.set(a[q],1);
  }
  var ans = 0;
  for(var k of map){
    ans += k[1];
  }
  return ans;
}