#include <cstdio>
#include <iostream>
#include <set>

using namespace std;

const int NMAX = 50000;

int a[NMAX];
int n, amin, amax, c;
set<int> s;

int main (){
//  freopen("tree.in","r",stdin);
  //freopen("tree.out","w",stdout);
  int n = 0;
  while (true) {
    int res = scanf("%d", &a[n]);
    if (res < 1) {
      break;
    }
    n++;

    //контроль правильности теста - повторов быть не должно
    c=s.size();
    s.insert(a[n-1]);
    if (s.size() == c) {cout << "ERROR!\n"; return 1;}

  }

  amin = amax = a[n-1];
  for (int i=n-2; i>=0; i--) {
    if (!(a[i+1]>a[i] && amin>a[i] || a[i+1]<a[i] && amax<a[i])) {
      cout << "NO\n";
      return 0;
    }
    if (a[i]<amin) amin=a[i];
    if (a[i]>amax) amax=a[i];
  }
  cout << "YES\n";
  return 0;
}
