import java.io.*;
import java.util.*;
import java.util.function.Function;

public class Main {

    static int N;
    static int[] U, V;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        U = new int[N-1];
        V = new int[N-1];
        for (int i = 0; i < N - 1; i++) {
            U[i] = sc.nextInt()-1;
            V[i] = sc.nextInt()-1;
        }
        A = sc.nextIntArray(N, -1);

        System.out.println(solve() ? "Yes" : "No");
    }

    static boolean solve() {
        if( A[0] != 0 ) return false;

        int[][] G = adjB(N, U, V);

        Map<Integer, Integer> parents = new HashMap<>();
        for (Node node : orderFromRoot(N, G, 0)) {
            parents.put(node.a, node.parent);
        }
        ArrayDeque<Integer> q = new ArrayDeque<>();
        for (int next : G[0]) {
            q.add(0);
        }

        int idx = 1;
        while(!q.isEmpty()) {
            int p = q.poll();
            int a = A[idx++];
            if( parents.get(a) != p ) {
                return false;
            }

            for (int next : G[a]) {
                if( next == p ) continue;

                q.add(a);
            }
        }
        return true;
    }

    static int[][] adjB(int n, int[] from, int[] to) {
        int[][] adj = new int[n][];
        int[] cnt = new int[n];
        for (int f : from) {
            cnt[f]++;
        }
        for (int t : to) {
            cnt[t]++;
        }
        for (int i = 0; i < n; i++) {
            adj[i] = new int[cnt[i]];
        }
        for (int i = 0; i < from.length; i++) {
            adj[from[i]][--cnt[from[i]]] = to[i];
            adj[to[i]][--cnt[to[i]]] = from[i];
        }
        return adj;
    }

    static Node[] orderFromRoot(int N, int[][] G, int root) {
        ArrayDeque<Node> q = new ArrayDeque<>();
        Node[] ret = new Node[N];
        int idx = 0;
        q.add(new Node(-1, root));
        while(!q.isEmpty()) {
            Node n = q.poll();
            ret[idx++] = n;
            for (int next : G[n.a]) {
                if( next == n.parent ) continue;

                q.add(new Node(n.a, next));
            }
        }
        return ret;
    }

    static class Node {
        int parent, a;

        public Node(int parent, int a) {
            this.parent = parent;
            this.a = a;
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        int[] nextIntArray(int n, int delta) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt() + delta;
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

    static <A> void writeLines(A[] as, Function<A, String> f) {
        PrintWriter pw = new PrintWriter(System.out);
        for (A a : as) {
            pw.println(f.apply(a));
        }
        pw.flush();
    }

    static void writeLines(int[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int a : as) pw.println(a);
        pw.flush();
    }

    static void writeLines(long[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (long a : as) pw.println(a);
        pw.flush();
    }

    static int max(int... as) {
        int max = Integer.MIN_VALUE;
        for (int a : as) max = Math.max(a, max);
        return max;
    }

    static int min(int... as) {
        int min = Integer.MAX_VALUE;
        for (int a : as) min = Math.min(a, min);
        return min;
    }

    static void debug(Object... args) {
        StringJoiner j = new StringJoiner(" ");
        for (Object arg : args) {
            if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));
            else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));
            else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));
            else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));
            else j.add(arg.toString());
        }
        System.err.println(j.toString());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class MicroWorld {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());

		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());

		int[] temp = new int[1000001];

		StringTokenizer st1 = new StringTokenizer(br.readLine());

		for (int i = 0; i < n; i++){

			temp[Integer.parseInt(st1.nextToken())]++;
		}

		int b = k + 1;

		for (int i = 1000000; i > 0; i--){

			if (temp[i] > 0){
				if (b <= k){
					n -= temp[i];
				}
				b = 1;
			}else{
				b++;
			}
		}

		System.out.println(n);

	}

}


/*
Keep solving problems.
*/

import java.util.*;
import java.io.*;

public class CFA {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

    int n;
    int m;
    char[][] mat;
    long base = 397;
    void solve() throws IOException {
        n = nextInt();
        m = nextInt();
        mat = new char[n][m];
        for (int i = 0; i < n; i++) {
            mat[i] = nextString().toCharArray();
        }

        int alpha = 26;
        long[] pow = new long[alpha];
        pow[0] = 1;
        for (int i = 1; i < alpha; i++) {
            pow[i] = pow[i - 1] * base % MOD;
        }

        long res = 0;
        for (int l = 0; l < m; l++) {
            //[l, r]
            long[] hash = new long[n];
            long[] mask = new long[n];
            for (int r = l; r < m; r++) {
                for (int i = 0; i < n; i++) {
                    hash[i] += pow[mat[i][r] - 'a'];
                    hash[i] %= MOD;
                    mask[i] = mask[i] ^ (1L << (mat[i][r] - 'a'));
                }

                int start = 0;
                while (start < n) {
                    if ((mask[start] & (mask[start] - 1)) != 0) {
                        start++;
                        continue;
                    }

                    int end = start;
                    List<Long> l1 = new ArrayList<>();
                    while (end < n && (mask[end] & (mask[end] - 1)) == 0) {
                        l1.add(hash[end]);
                        end++;
                    }

                    start = end;
                    res += manacher(l1);
                }
            }
        }

        outln(res);
    }

    long manacher(List<Long> arr) {
        int len = arr.size();
        long[] t = new long[len * 2 + 3];
        t[0] = -1;
        t[len * 2 + 2] = -2;
        for (int i = 0; i < len; i++) {
            t[2 * i + 1] = -3;
            t[2 * i + 2] = arr.get(i);
        }

        t[len * 2 + 1] = -3;
        int[] p = new int[t.length];
        int center = 0, right = 0;
        for (int i = 1; i < t.length - 1; i++) {
            int mirror = 2 * center - i;
            if (right > i) {
                p[i] = Math.min(right - i, p[mirror]);
            }

            // attempt to expand palindrome centered at i
            while (t[i + (1 + p[i])] == t[i - (1 + p[i])]) {
                p[i]++;
            }

            // if palindrome centered at i expands past right,
            // adjust center based on expanded palindrome.
            if (i + p[i] > right) {
                center = i;
                right = i + p[i];
            }
        }

        long res = 0;
        for (int i = 0; i < 2 * len; i++) {
            int parLength = p[i + 2];
            if (i % 2 == 0) {
                res += (parLength + 1) / 2;
            }
            else {
                res += parLength / 2;
            }
        }

        return res;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    private void formatPrint(double val) {
        outln(String.format("%.9f%n", val));
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.io.InputStream ;
import java.util.InputMismatchException;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        //Scanner sc = new Scanner();
        Reader in = new Reader();
        Main solver = new Main();
        solver.solve(out, in);
        out.flush();
        out.close();

    }

    void solve(PrintWriter out, Reader in) throws IOException{
        int n = in.nextInt();
        int m = in.nextInt();

        int[] vert = new int[n+1];
        for(int i=0 ;i<n ;i++) vert[i] = in.nextInt();
        vert[n] = (int)1e9;

        int cnt=0,x,y;
        ArrayList<Integer> arr = new ArrayList<>();
        for(int i=0 ;i<m ;i++) {
            x = in.nextInt();
            y = in.nextInt();
            in.nextInt();

            if(x==1) arr.add(y);
        }

        horz = new int[arr.size()];
        for(int i=0 ;i<arr.size();i++) horz[i] = arr.get(i);

        Arrays.sort(horz);
        Arrays.sort(vert);

        int ans = 2*(int)1e5+10;
        for(int i=0 ;i<=n ;i++){
            int lesshorz = bs(vert[i],horz.length);
            ans = Math.min(ans,i+horz.length-lesshorz-1);
        }
        out.println(ans);
    }

    static int[] horz;

    static int bs(int num,int m){
        int mid,lo=0,hi=m-1,r=-1;

        while(lo<=hi){
            mid = (lo+hi)/2;
            if(horz[mid]<num){
                lo = mid+1;
                r = mid;
            }else{
                hi =mid-1;
            }
        }
        return r;
    }

    static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();

        }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.awt.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), m = scanner.nextInt();
        int[] vertical = new int[n];

        for (int i = 0; i < n; i++) {
            vertical[i] = scanner.nextInt();
        }

        Arrays.sort(vertical);

        ArrayList<Integer> horisontal = new ArrayList<>();
        int amount = 0;
        for (int i = 0; i < m; i++) {
            int x1 = scanner.nextInt(), x2 = scanner.nextInt(), y = scanner.nextInt();
            if (x1 == 1) {
                amount++;
                horisontal.add(x2);
            }
        }

        Collections.sort(horisontal);

        if (amount == 0) {
            System.out.println(0);
            return;
        }

        int minVal = amount, horSize = horisontal.size(), verLen = vertical.length;
        int h = 0, v = 0;

        for (; v < verLen && h < horSize; ) {

           while (h < horSize && horisontal.get(h) < vertical[v]){
               h++;
               amount--;
           }
           minVal = Math.min(minVal, amount + v);

            while (h < horSize && v < verLen && horisontal.get(h) >= vertical[v]){
                minVal = Math.min(minVal, amount + v);
                v++;
            }

        }

        if(horisontal.get(horSize - 1) < 1E9){
            minVal = Math.min(minVal, v);
        }

        System.out.println(minVal);

    }
}


import java.io.*;
import java.util.*;

public class A4 {

    public BufferedReader input;
    public PrintWriter output;
    public StringTokenizer stoken = new StringTokenizer("");

    public static void main(String[] args) throws IOException {
        new A4();
    }

    A4() throws IOException {
        input = new BufferedReader(new InputStreamReader(System.in));
        output = new PrintWriter(System.out);
        run();
        input.close();
        output.close();
    }

    private void run() throws IOException {
        int n = Math.toIntExact(nextLong());
        int m = Math.toIntExact(nextLong());
        int[] coor = new int[n + 1];
        int[] ss = new int[n + 1];
        for (int i = 0; i < n; i++) {
            coor[i] = Math.toIntExact(nextLong());
        }
        coor[n] = 1000000000;
        Arrays.sort(coor);
        for (int i = 0; i < m; i++) {
            long x1 = nextLong();
            long x2 = nextLong();
            nextLong();
            if (x1 == 1 && x2 >= coor[0]) {
                int l = 0;
                int r = n + 1;
                while (r - l > 1) {
                    int mi = (r + l) / 2;
                    if (coor[mi] > x2) {
                        r = mi;
                    } else {
                        l = mi;
                    }
                }
                ss[l]++;
            }
        }
        long[] ans = new long[n + 1];
        ans[n] = ss[n] + n;
        long min = ans[n];
        for (int i = n - 1; i > -1; i--) {
            ans[i] = ans[i + 1] - 1 + ss[i];
            if (ans[i] < min) {
                min = ans[i];
            }
        }
        System.out.println(min);
    }

    private Long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    private String nextString() throws IOException {
        while (!stoken.hasMoreTokens()) {
            String st = input.readLine();
            stoken = new StringTokenizer(st);
        }
        return stoken.nextToken();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class loser
{
    static class InputReader {
        public BufferedReader br;
        public StringTokenizer token;
        public InputReader(InputStream stream)
        {
            br=new BufferedReader(new InputStreamReader(stream),32768);
            token=null;
        }

        public String next()
        {
            while(token==null || !token.hasMoreTokens())
            {
                try
                {
                    token=new StringTokenizer(br.readLine());
                }
                catch(IOException e)
                {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }
    }
    static class card{
        int l;
        int r;
        public card(int ch,int i)
        {
            this.l=ch;
            this.r=i;
        }
    }
    static class sort implements Comparator<card>
    {
        public int compare(card o1,card o2)
        {
            if(o1.l!=o2.l)
                return (int)(o1.l-o2.l);
            else
                return (int)(o1.r-o2.r);
        }
    }
    static void shuffle(long a[])
    {
        List<Long> l=new ArrayList<>();
        for(int i=0;i<a.length;i++)
            l.add(a[i]);
        Collections.shuffle(l);
        for(int i=0;i<a.length;i++)
            a[i]=l.get(i);
    }

    /*static long gcd(long a,long b)
    {
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
    }
    static int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE,ans3=Integer.MAX_VALUE,ans4=Integer.MAX_VALUE;
    static boolean v[]=new boolean[101];
    static void dfs(Integer so,Set<Integer> s[]){
    if(!v[so.intValue()])
    {
    v[so]=true;
    for(Integer h:s[so.intValue()])
    {
    if(!v[h.intValue()])
    dfs(h,s);
    }
    }
    }
    static class Print{
    public PrintWriter out;
    Print(OutputStream o)
    {
    out=new PrintWriter(o);
    }
    }
    static int CeilIndex(int A[], int l, int r, int key)
    {
    while (r - l > 1) {
    int m = l + (r - l) / 2;
    if (A[m] >= key)
    r = m;
    else
    l = m;
    }

    return r;
    }

    static int LongestIncreasingSubsequenceLength(int A[], int size)
    {
    // Add boundary case, when array size is one
    int[] tailTable = new int[size];
    int len; // always points empty slot
    tailTable[0] = A[0];
    len = 1;
    for (int i = 1; i < size; i++) {
    if (A[i] < tailTable[0])
    // new smallest value
    tailTable[0] = A[i];

    else if (A[i] > tailTable[len - 1])
    // A[i] wants to extend largest subsequence
    tailTable[len++] = A[i];

    else
    // A[i] wants to be current end candidate of an existing
    // subsequence. It will replace ceil value in tailTable
    tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
    }
    return len;
    }*/
    /*static int binary(int n)
    {
    int s=1;
    while(n>0)
    {
    s=s<<1;
    n--;
    }
    return s-1;
    }
    static StringBuilder bin(int i,int n)
    {
    StringBuilder s=new StringBuilder();
    while(i>0)
    {
    s.append(i%2);
    i=i/2;
    }
    while(s.length()!=n)
    {
    s.append(0);
    }
    return s.reverse();
    }*/
    static boolean valid(int i,int j,int n,int m)
    {
        if(i<n && i>=0 && j<m && j>=0)
            return true;
        else
            return false;
    }

    public static void main(String[] args)
    {
        InputReader sc=new InputReader(System.in);
        int n=sc.nextInt();
        int s=sc.nextInt();
        card c[]=new card[n];
        for(int i=0;i<n;i++)
        {
            int x=sc.nextInt();
            int y=sc.nextInt();
            c[i]=new card(x,y);
        }
        Arrays.sort(c,new sort());
        int time=0;
        for(int i=n-1;i>=0;i--)
        {
            time+=s-c[i].l;
            if((c[i].r-time)>0)
            time+=c[i].r-time;
            s=c[i].l;
        }
        if(c[0].l!=0)
        time+=c[0].l;
        System.out.println(time);
    }
}


import javafx.util.Pair;

import java.io.*;
import java.util.*;

public class Beacon8 {
    public static void main(String[] args) throws IOException {
//        int[] arr = {1, 3, 7, 18};
//        int bIndex = Arrays.binarySearch(arr, 4);
//        System.out.println(bIndex);

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Map<Integer, Integer> beacons = new TreeMap<>();

        for (int i = 0; i < n; i++) {
            int index = scan.nextInt();
            int power = scan.nextInt();
            beacons.put(index, power);
        }
        int[] indicesArr = new int[n];
        int arrInd = 0;
        for (int index : beacons.keySet()) {
            indicesArr[arrInd] = index;
            arrInd++;
        }
       // Integer[] indicesArr = ((Integer[])beacons.keySet().toArray());
        int[] nDestroys = new int[n];
        for (int i = 0; i < n; i++) {
            int bIndex = Arrays.binarySearch(indicesArr, indicesArr[i] - beacons.get(indicesArr[i]));
            if (bIndex < 0)
                bIndex = -(bIndex + 1);
            nDestroys[i] = i - bIndex;
        }
        int[] totalBeacons = new int[n];
        int maxBeacons = 1;
        totalBeacons[0] = 1;
        for (int i = 1; i < n; i++) {
            if (nDestroys[i] == 0)
                totalBeacons[i] = totalBeacons[i - 1] + 1;
            else {
                if ((i - nDestroys[i] - 1) >= 0)
                    totalBeacons[i] = totalBeacons[i - nDestroys[i] - 1] + 1;
                else
                    totalBeacons[i] = 1;
            }
               // totalBeacons[i] = totalBeacons[i - nDestroys[i]] + 1;
            //totalBeacons[i] = i - nDestroys[i] + totalBeacons[i - nDestroys[i]] + 1;
            if(totalBeacons[i] > maxBeacons)
                maxBeacons = totalBeacons[i];
        }
//        System.out.println("\ntotalBeacons array");
//        for (int i = 0; i < n; i++) {
//            System.out.print(totalBeacons[i] + " ");
//        }
//        if (maxBeacons == -1)
//            System.out.println(n);
        System.out.println(n - maxBeacons);
    }

}


import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class ChainReaction implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  private class Beacon implements Comparable<Beacon> {
    private int position, range, score;

    private Beacon(int position, int range) {
      this.position = position;
      this.range = range;
    }

    public void setScore(int score) {
      this.score = score;
    }

    @Override
    public int compareTo(Beacon o) {
      return Integer.compare(this.position, o.position);
    }
  }

  public void solve() {
    int n = in.ni();
    if (n == 1) {
      out.println(0);
      return;
    }
    beacons = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      beacons.add(new Beacon(in.ni(), in.ni()));
    }
    beacons.sort(Comparator.naturalOrder());
    for (int i = 1; i < n; i++) {
      int left = 0, right = i - 1, position = beacons.get(i).position, range = beacons.get(i).range;
      int leftmost = i;
      while (left <= right) {
        int mid = left + (right - left) / 2;
        if (position - range <= beacons.get(mid).position) {
          leftmost = Math.min(leftmost, mid);
          right = mid - 1;
        } else {
          left = mid + 1;
        }
      }
      beacons.get(i).setScore(i - leftmost);
    }
    dp = new Integer[n];
    int ans = Integer.MAX_VALUE;
    for (int i = n - 1; i >= 0; i--) {
      ans = Math.min(n - 1 - i + recurse(i), ans);
    }
    out.println(ans);
  }

  private List<Beacon> beacons;
  private Integer[] dp;

  private int recurse(int idx) {
    if (idx <= 0) return 0;

    if (dp[idx] != null) return dp[idx];

    int destroyed = beacons.get(idx).score;
    int ans = destroyed + recurse(idx - destroyed - 1);
    return dp[idx] = ans;
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (ChainReaction instance = new ChainReaction()) {
      instance.solve();
    }
  }
}


import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] point = new int[n][];
        for(int i=0;i<n;i++) point[i] = new int[]{sc.nextInt(),sc.nextInt()};
        Arrays.sort(point,(a,b)->((a[0]-a[1])-(b[0]-b[1])));
        TreeMap<Integer,Integer> tm = new TreeMap<>();
        int ans = 0;
        for(int i=n-1;i>=0;i--){
            int x = point[i][0], w = point[i][1];
            Map.Entry<Integer,Integer> cur =  tm.ceilingEntry(x+w);
            int curRes;
            if(cur==null) curRes = 1;
            else curRes = cur.getValue()+1;
            ans = Math.max(ans,curRes);
            Map.Entry<Integer,Integer> upper = tm.ceilingEntry(x-w);
            if(upper==null||upper.getValue()<curRes) tm.put(x-w,curRes);
            //Integer key = tm.
        }
        System.out.println(ans);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            TaskD.Pair[] p = new TaskD.Pair[n];
            for (int i = 0; i < n; ++i) {
                p[i] = new TaskD.Pair(in.nextLong(), in.nextLong());
            }
            Arrays.sort(p);
            int last = 0;
            int ans = 1;
            for (int i = 1; i < n; ++i) {
                if (p[i].x - p[i].w >= p[last].x + p[last].w) {
                    last = i;
                    ++ans;
                }
            }
            out.println(ans);
        }

        static class Pair implements Comparable<TaskD.Pair> {
            long x;
            long w;

            public Pair(long x, long w) {
                this.x = x;
                this.w = w;
            }

            public int compareTo(TaskD.Pair o) {
                return Long.compare(x + w, o.x + o.w);
            }

            public String toString() {
                return x + " " + w;
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author aryssoncf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            try {
                int n = in.readInt();
                int[] x = new int[n], w = new int[n];
                in.readIntArrays(x, w);
                int[] begin = new int[n], end = new int[n];
                Arrays.setAll(begin, i -> x[i] - w[i]);
                Arrays.setAll(end, i -> x[i] + w[i]);
                int m = ArrayUtils.compress(begin, end).length;
                int[] dp = new int[m + 1], order = ArrayUtils.order(end);
                int idx = 0;
                for (int i = 0; i < m; i++) {
                    if (i > 0) {
                        dp[i] = dp[i - 1];
                    }
                    while (idx < n && end[order[idx]] == i) {
                        dp[i] = Math.max(dp[i], dp[begin[order[idx]]] + 1);
                        idx++;
                    }
                }
                int res = dp[m - 1];
                out.printLine(res);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    static class Sorter {
        private static final int INSERTION_THRESHOLD = 16;

        private Sorter() {
        }

        public static void sort(IntList list, IntComparator comparator) {
            quickSort(list, 0, list.size() - 1, (Integer.bitCount(Integer.highestOneBit(list.size()) - 1) * 5) >> 1,
                    comparator);
        }

        private static void quickSort(IntList list, int from, int to, int remaining, IntComparator comparator) {
            if (to - from < INSERTION_THRESHOLD) {
                insertionSort(list, from, to, comparator);
                return;
            }
            if (remaining == 0) {
                heapSort(list, from, to, comparator);
                return;
            }
            remaining--;
            int pivotIndex = (from + to) >> 1;
            int pivot = list.get(pivotIndex);
            list.swap(pivotIndex, to);
            int storeIndex = from;
            int equalIndex = to;
            for (int i = from; i < equalIndex; i++) {
                int value = comparator.compare(list.get(i), pivot);
                if (value < 0) {
                    list.swap(storeIndex++, i);
                } else if (value == 0) {
                    list.swap(--equalIndex, i--);
                }
            }
            quickSort(list, from, storeIndex - 1, remaining, comparator);
            for (int i = equalIndex; i <= to; i++) {
                list.swap(storeIndex++, i);
            }
            quickSort(list, storeIndex, to, remaining, comparator);
        }

        private static void heapSort(IntList list, int from, int to, IntComparator comparator) {
            for (int i = (to + from - 1) >> 1; i >= from; i--) {
                siftDown(list, i, to, comparator, from);
            }
            for (int i = to; i > from; i--) {
                list.swap(from, i);
                siftDown(list, from, i - 1, comparator, from);
            }
        }

        private static void siftDown(IntList list, int start, int end, IntComparator comparator, int delta) {
            int value = list.get(start);
            while (true) {
                int child = ((start - delta) << 1) + 1 + delta;
                if (child > end) {
                    return;
                }
                int childValue = list.get(child);
                if (child + 1 <= end) {
                    int otherValue = list.get(child + 1);
                    if (comparator.compare(otherValue, childValue) > 0) {
                        child++;
                        childValue = otherValue;
                    }
                }
                if (comparator.compare(value, childValue) >= 0) {
                    return;
                }
                list.swap(start, child);
                start = child;
            }
        }

        private static void insertionSort(IntList list, int from, int to, IntComparator comparator) {
            for (int i = from + 1; i <= to; i++) {
                int value = list.get(i);
                for (int j = i - 1; j >= from; j--) {
                    if (comparator.compare(list.get(j), value) <= 0) {
                        break;
                    }
                    list.swap(j, j + 1);
                }
            }
        }

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void set(int index, int value);

        public abstract void addAt(int index, int value);

        public abstract void removeAt(int index);

        default public void swap(int first, int second) {
            if (first == second) {
                return;
            }
            int temp = get(first);
            set(first, get(second));
            set(second, temp);
        }

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

        default public void add(int value) {
            addAt(size(), value);
        }

        default public IntList sort(IntComparator comparator) {
            Sorter.sort(this, comparator);
            return this;
        }

        default IntList unique() {
            int last = Integer.MIN_VALUE;
            IntList result = new IntArrayList();
            int size = size();
            for (int i = 0; i < size; i++) {
                int current = get(i);
                if (current != last) {
                    result.add(current);
                    last = current;
                }
            }
            return result;
        }

        default public IntList subList(final int from, final int to) {
            return new IntList() {
                private final int shift;
                private final int size;

                {
                    if (from < 0 || from > to || to > IntList.this.size()) {
                        throw new IndexOutOfBoundsException("from = " + from + ", to = " + to + ", size = " + size());
                    }
                    shift = from;
                    size = to - from;
                }

                public int size() {
                    return size;
                }

                public int get(int at) {
                    if (at < 0 || at >= size) {
                        throw new IndexOutOfBoundsException("at = " + at + ", size = " + size());
                    }
                    return IntList.this.get(at + shift);
                }

                public void addAt(int index, int value) {
                    throw new UnsupportedOperationException();
                }

                public void removeAt(int index) {
                    throw new UnsupportedOperationException();
                }

                public void set(int at, int value) {
                    if (at < 0 || at >= size) {
                        throw new IndexOutOfBoundsException("at = " + at + ", size = " + size());
                    }
                    IntList.this.set(at + shift, value);
                }

                public IntList compute() {
                    return new IntArrayList(this);
                }
            };
        }

    }

    static interface IntComparator {
        IntComparator DEFAULT = Integer::compare;

        int compare(int first, int second);

    }

    static class Range {
        public static IntList range(int from, int to) {
            int[] result = new int[Math.abs(from - to)];
            int current = from;
            if (from <= to) {
                for (int i = 0; i < result.length; i++) {
                    result[i] = current++;
                }
            } else {
                for (int i = 0; i < result.length; i++) {
                    result[i] = current--;
                }
            }
            return new IntArray(result);
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        IntIterator intIterator();

        default Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public void readIntArrays(int[]... arrays) {
            for (int i = 0; i < arrays[0].length; i++) {
                for (int j = 0; j < arrays.length; j++) {
                    arrays[j][i] = readInt();
                }
            }
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);

        }

    }

    static interface IntCollection extends IntStream {
        public int size();

        default public void add(int value) {
            throw new UnsupportedOperationException();
        }

        default public int[] toArray() {
            int size = size();
            int[] array = new int[size];
            int i = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                array[i++] = it.value();
            }
            return array;
        }

        default public IntCollection addAll(IntStream values) {
            for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {
                add(it.value());
            }
            return this;
        }

    }

    static class IntArray extends IntAbstractStream implements IntList {
        private int[] data;

        public IntArray(int[] arr) {
            data = arr;
        }

        public int size() {
            return data.length;
        }

        public int get(int at) {
            return data[at];
        }

        public void addAt(int index, int value) {
            throw new UnsupportedOperationException();
        }

        public void removeAt(int index) {
            throw new UnsupportedOperationException();
        }

        public void set(int index, int value) {
            data[index] = value;
        }

    }

    static class ArrayUtils {
        public static int[] range(int from, int to) {
            return Range.range(from, to).toArray();
        }

        public static int[] createOrder(int size) {
            return range(0, size);
        }

        public static int[] sort(int[] array, IntComparator comparator) {
            return sort(array, 0, array.length, comparator);
        }

        public static int[] sort(int[] array, int from, int to, IntComparator comparator) {
            if (from == 0 && to == array.length) {
                new IntArray(array).sort(comparator);
            } else {
                new IntArray(array).subList(from, to).sort(comparator);
            }
            return array;
        }

        public static int[] order(final int[] array) {
            return sort(createOrder(array.length), (first, second) -> Integer.compare(array[first], array[second]));
        }

        public static int[] unique(int[] array) {
            return new IntArray(array).unique().toArray();
        }

        public static int[] compress(int[]... arrays) {
            int totalLength = 0;
            for (int[] array : arrays) {
                totalLength += array.length;
            }
            int[] all = new int[totalLength];
            int delta = 0;
            for (int[] array : arrays) {
                System.arraycopy(array, 0, all, delta, array.length);
                delta += array.length;
            }
            sort(all, IntComparator.DEFAULT);
            all = unique(all);
            for (int[] array : arrays) {
                for (int i = 0; i < array.length; i++) {
                    array[i] = Arrays.binarySearch(all, array[i]);
                }
            }
            return all;
        }

    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static class IntArrayList extends IntAbstractStream implements IntList {
        private int size;
        private int[] data;

        public IntArrayList() {
            this(3);
        }

        public IntArrayList(int capacity) {
            data = new int[capacity];
        }

        public IntArrayList(IntCollection c) {
            this(c.size());
            addAll(c);
        }

        public IntArrayList(IntStream c) {
            this();
            if (c instanceof IntCollection) {
                ensureCapacity(((IntCollection) c).size());
            }
            addAll(c);
        }

        public IntArrayList(IntArrayList c) {
            size = c.size();
            data = c.data.clone();
        }

        public IntArrayList(int[] arr) {
            size = arr.length;
            data = arr.clone();
        }

        public int size() {
            return size;
        }

        public int get(int at) {
            if (at >= size) {
                throw new IndexOutOfBoundsException("at = " + at + ", size = " + size);
            }
            return data[at];
        }

        private void ensureCapacity(int capacity) {
            if (data.length >= capacity) {
                return;
            }
            capacity = Math.max(2 * data.length, capacity);
            data = Arrays.copyOf(data, capacity);
        }

        public void addAt(int index, int value) {
            ensureCapacity(size + 1);
            if (index > size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size) {
                System.arraycopy(data, index, data, index + 1, size - index);
            }
            data[index] = value;
            size++;
        }

        public void removeAt(int index) {
            if (index >= size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size - 1) {
                System.arraycopy(data, index + 1, data, index, size - index - 1);
            }
            size--;
        }

        public void set(int index, int value) {
            if (index >= size) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            data[index] = value;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

    }

    static abstract class IntAbstractStream implements IntStream {
        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }
}


import java.util.*;

public class A{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Integer> v = new TreeSet<Integer>();
        for(int i=0;i<n;i++) v.add(sc.nextInt());
        Iterator<Integer> it = v.iterator();
        it.next();
        it.remove();
        System.out.println(v.isEmpty() ? "NO" : v.iterator().next());
    }
}


import java.util.Scanner;

public class Seq2 {

    static void metod() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = in.nextInt();

        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] < min)
                min = a[i];
        }

        int min2 = min;
        boolean t = false;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != min) {
                if (!t) {
                    min2 = a[i];
                    t = true;
                } else {
                    if (min2 > a[i])
                        min2 = a[i];
                }
            }
        }

        System.out.println((min == min2) ? "NO" : min2);
    }

    public static void main(String[] args) {
        Seq2.metod();
    }
}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    private static Parser in;
    private static PrintWriter out;

    public static void main(String[] args) {
        in = new Parser(System.in);
        out = new PrintWriter(System.out);

        int n= in.nextInt();
        int min = 101;
        boolean b = false;
        int pmin = 101;
        int t= 0 ;
        for(int i=0; i<n; i++){
            t = in.nextInt();

            if (t<min){if(min != pmin)b=true; if(b) pmin = min;  min = t;  continue;}
            if (t>min && t<pmin){b=true; pmin = t;  continue;}
            if (t>min && !b){b=true; pmin = t;  continue;}
            //if (b){if(t<pmin){pmin = t; continue;}}
            //out.print(min);
            //out.print(pmin);
        }
        if (b) System.out.println(pmin); else System.out.println("NO");
        //out.flush();
    }
}

class Parser {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Parser(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
    }
    public String nextString(int size) {
        byte[] ch = new byte[size];
        int point = 0;
        try {
            byte c = read();
            while (c == ' ' || c == '\n' || c=='\r')
                c = read();
            while (c != ' ' && c != '\n' && c!='\r') {
                ch[point++] = c;
                c = read();
            }
        } catch (Exception e) {}
        return new String(ch,0,point);
        }
    public int nextInt() {
    int ret = 0;
    boolean neg;
    try {
        byte c = read();
        while (c <= ' ')
            c = read();
        neg = c == '-';
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');

    if (neg) return -ret;
    } catch (Exception e) {}
    return ret;
    }
    public long nextLong() {
        long ret = 0;
        boolean neg;
        try {
            byte c = read();
            while (c <= ' ')
                c = read();
            neg = c == '-';
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
                c = read();
            } while (c > ' ');

        if (neg) return -ret;
        } catch (Exception e) {}
        return ret;
        }
    private void fillBuffer() {
        try {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        } catch (Exception e) {}
        if (bytesRead == -1) buffer[0] = -1;
    }

    private byte read() {
        if (bufferPointer == bytesRead) fillBuffer();
        return buffer[bufferPointer++];
    }
}


import java.util.*;

public class A
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        int[] a = new int[n];

        for(int i=0;i < n;i++)
            a[i] = scan.nextInt();

        Arrays.sort(a);

        int min = a[0];

        for(int i=1;i < n;i++)
        {
            if(a[i] > min)
            {
                System.out.println(a[i]);
                return;
            }
        }

        System.out.println("NO");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class A {
    public static void main(String[] args) throws IOException {
        new A().run();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        Set<Integer> set = new TreeSet<Integer>();

        for (int i = 0; i < n; i++) {
            set.add(nextInt());
        }
        set.remove(set.iterator().next());
        PrintWriter pw = new PrintWriter(System.out);
        if (set.isEmpty()) {
            pw.println("NO");
        } else {
            pw.println(set.iterator().next());
        }
        pw.close();
    }

    int nextInt() throws IOException {
        while (!st.hasMoreElements()) {
            st = new StringTokenizer(br.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }

}


import java.util.*;
import java.io.*;
public class Main{

        BufferedReader in;
        StringTokenizer str = null;
        PrintWriter out;

        private String next() throws Exception{
                if (str == null || !str.hasMoreTokens())
                        str = new StringTokenizer(in.readLine());
                return str.nextToken();
        }

        private int nextInt() throws Exception{
                return Integer.parseInt(next());
        }

        private long nextLong() throws Exception{
                return Long.parseLong(next());
        }

        private double nextDouble() throws Exception{
                return Double.parseDouble(next());
        }

        public void run() throws Exception{
                in = new BufferedReader(new InputStreamReader(System.in));//new FileReader();
                out = new PrintWriter(System.out);//new File();
                int n = nextInt();
                HashSet<Integer> hs = new HashSet<Integer>();
                for(int i=0;i<n;i++) hs.add(nextInt());
                if (hs.size() == 1){
                  out.println("NO");
                  out.close();
                  return;
                }
                int a[] = new int[hs.size()];
                int yk = 0;
                for(int i:hs) a[yk++] = i;
                Arrays.sort(a);
                out.println(a[1]);
                out.close();
        }

        public static void main(String args[]) throws Exception{
                new Main().run();
        }
}


import java.util.*;

public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                TreeSet<Integer> set = new TreeSet<Integer>();

                for(int i=0;i<n;i++){
                        set.add(sc.nextInt());
                }

                if(set.size() >= 2)
                        System.out.println(set.toArray()[1]);
                else
                        System.out.println("NO");
        }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;

/**
 * @author Egor Kulikov (egor@egork.net)
 *         Created on 14.03.2010
 */
public class TaskA implements Runnable {
	private InputReader in;
	private PrintWriter out;

	public static void main(String[] args) {
//		new Thread(new Template()).start();
		new TaskA().run();
	}

	public TaskA() {
//		String id = getClass().getName().toLowerCase();
//		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
//		} catch (FileNotFoundException e) {
//			throw new RuntimeException();
//		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	public void run() {
//        int numTests = in.readInt();
//        for (int testNumber = 0; testNumber < numTests; testNumber++) {
//			out.print("Case " + (testNumber + 1) + ": ");
//        }
		int n = in.readInt();
		int min = 101;
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			min = Math.min(min, a[i] = in.readInt());
		int ans = 101;
		for (int i = 0; i < n; i++) {
			if (a[i] > min)
				ans = Math.min(ans, a[i]);
		}
		if (ans == 101)
			out.println("NO");
		else
			out.println(ans);
		out.close();
	}

	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1000];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class VtoraiaStat implements Runnable {

    boolean isLocalMode = false;

    private void doJob() throws Exception {
       int n  = nextInt();
        int[] r = new int[n];
        for(int i =0;i<n;i++){
            r[i]=nextInt();
        }

        Arrays.sort(r);
        int m = r[0];
        for(int i=0;i<n;i++){
            if(r[i]!=m){
                writer.write(""+r[i]);
                return;
            }
        }
        writer.write("NO");
    }

    public static void main(String[] args) {
        new VtoraiaStat().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(getReader());
            tokenizer = null;
            writer = new PrintWriter(System.out);
            //do job
            doJob();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public Reader getReader() throws FileNotFoundException {
        if (isLocalMode) {
            return new FileReader("input.txt");
        } else {
            return new InputStreamReader(System.in);
        }
    }
}


import java.io.*;

public class Main {

    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int iTotTerm, i, j, iSml = 0, iPos = 0;
        iTotTerm = Integer.parseInt(br.readLine());
        String seq[];
        seq = br.readLine().split(" ");
        int iSeq[] = new int[iTotTerm];
        for (i = 0; i < iTotTerm; i++) {
            iSeq[i] = Integer.parseInt(seq[i]);
        }
        for (i = 0; i < iTotTerm; i++) {
            iSml = iSeq[i];
            iPos = i;
            for (j = i; j < iTotTerm; j++) {
                if (iSeq[j] < iSml) {
                    iSml = iSeq[j];
                    iPos = j;
                }
            }
            iSeq[iPos] = iSeq[i];
            iSeq[i] = iSml;
            if (i != 0 && iSeq[i - 1] != iSeq[i]) {
                break;
            }
        }
        if (iSml != iSeq[0]) {
            System.out.print(iSml);
        } else {
            System.out.print("NO");
        }
    }
}


import java.io.*;
import java.util.*;

public class Main{
	public static void main(String []args){
		Scanner cin = new Scanner( System.in );
		int n  = cin.nextInt();
		int [] num = new int [ n ];

		for (int i=0; i<n; i++)
			num[i] = cin.nextInt();

		Arrays.sort( num );

		int i = 0;
		while ( i < n ){
			if ( num[i] != num[0] ) break;
			i++;
		}

		if ( i == n ) System.out.println("NO");
		else System.out.println(num[i]);
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Blah
{
    public static void main(String args[])
    {
	Scanner c = new Scanner(System.in);
	String number = c.nextLine();
	int i = Integer.parseInt(number);
	if (i == 1)
	    {
		System.out.println("NO");
		return;
	    }
	String line = c.nextLine();
	String[] arr = line.split(" ");
	int[] array = new int[i];
	for (int j = 0; j < i; j++)
	    {
		array[j] = Integer.parseInt(arr[j]);
	    }
        int min = array[0];
	int second = 0;
	boolean thing = false;
	for (int j = 0; j < i; j++)
	    {
		if (!thing && array[j] > min)
		    {
			second = array[j];
			thing = true;
		    }
		if (array[j] < min)
		    {
			second = min;
			min = array[j];
			thing = true;
		    }
		else if (thing && array[j] > min && array[j] < second)
		    second = array[j];
	    }
	if (!thing)
	    System.out.println("NO");
	else
	    System.out.println(second);
	return;
    }
}


import java.util.Scanner;

public class prob1 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		if(n == 1)
		{
//			throw new RuntimeException();
			int m = input.nextInt();
			System.out.println("NO");
//			System.out.println(input.next());
			return;
		}
		int[] num = new int[n];
		boolean flag  = false;
		for(int i = 0; i < n; i++)
		{
			num[i] = input.nextInt();
			if(num[i] != num[0])
				flag = true;
		}
		if(!flag)
		{
			System.out.println("NO");
			return;
		}
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++)
			if(num[i] < min)
				min = num[i];
		int min2 = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++)
			if(num[i] <= min2 && num[i] > min)
				min2 = num[i];
		System.out.println(min2);

	}
}


//package codeforces.br22;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * User: Kandy
 * Date: 29.06.2010
 * Time: 21:07:24
 */
public class ProblemA {
    public void solve() {
        boolean oj = true;

        try {
            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("A.in");
            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("A.out");
            BufferedReader br = new BufferedReader(reader);
            StreamTokenizer st = new StreamTokenizer(reader);
            PrintWriter out = new PrintWriter(writer);

            MyTokenizer tok = new MyTokenizer(br.readLine());
            int n = (int)tok.getNum();
            tok =new MyTokenizer(br.readLine());
            List<Integer> a = new ArrayList<Integer>();
            for(int i=0;i<n;i++) {
                int r = (int)tok.getNum();
                if (!a.contains(r)) {
                    a.add(r);
                }
            }
            Collections.sort(a);
            if (a.size() < 2) {
                out.printf("NO");
            } else {
                out.printf("%d", a.get(1));
            }

            br.close();
            out.close();
            reader.close();
            writer.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        finally {
        }
    }

    public static void main(String[] args) {
        ProblemA f = new ProblemA();
        f.solve();
    }

    private class MyTokenizer {
        private String s;
        private int cur;

        public MyTokenizer(String s) {
            this.s = s;
            cur = 0;
        }

        public void skip() {
            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\n')) {
                cur++;
            }
        }

        public double getNum() {
            skip();
            String snum = "";
            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {
                snum += s.charAt(cur);
                cur++;
            }
            return Double.valueOf(snum);
        }

        public String getString() {
            skip();
            String s2 = "";
            while (cur < s.length() && (((s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) || ((s.charAt(cur) >= 'A' && s.charAt(cur) <= 'Z')))) {
                s2 += s.charAt(cur);
                cur++;
            }
            return s2;
        }

        public char getCurrentChar() throws Exception {
            if (cur < s.length())
                return s.charAt(cur);
            else
                throw new Exception("Current character out of string length");
        }

        public void moveNextChar() {
            if (cur < s.length())
                cur++;
        }

        public boolean isFinished() {
            return cur >= s.length();
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main2 {
    public static void main(String[] args) throws Exception {
        new Main2().run();
    }

    public void solve() throws Exception {
        n = nextInt();
        int a[]= new int[n], pos = 1;
        for(int i=0; i<n; i++)
            a[i] = nextInt();
        Arrays.sort(a);
        if(n == 1){
            out.println("NO"); return;
        }
        boolean has = false;
        for(; pos<n; pos++){
            if(a[pos] != a[0]){
                has = true;
                break;
            }
        }
        if(!has){
            out.println("NO");
        }
        else{
            out.println(a[pos]);
        }
    }
    public int n, m;

    public void run() throws Exception {
        inter = new StreamTokenizer(new BufferedReader(new InputStreamReader(
                System.in)));
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }
    public BufferedReader in;
    public StreamTokenizer inter;
    public PrintWriter out;

    public int nextInt() throws Exception {
        inter.nextToken();
        return (int) inter.nval;
    }
    public String nextLine() throws Exception{
        return in.readLine();
    }
}


import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int first = Integer.MAX_VALUE, second = Integer.MAX_VALUE;

        for (int i = 0, x; i < N; ++i) {
            x = sc.nextInt();
            if (x < first) {
                second = first;
                first = x;
            } else if (x > first && x < second) {
                second = x;
            }
        }

        if (second == Integer.MAX_VALUE)
            System.out.println("NO");
        else
            System.out.println(second);
    }

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

public class A {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Integer> set = new HashSet<Integer>();

        for ( int i = 0 ; i < n ; ++i ) {
            set.add(sc.nextInt());
        } // for i

        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        if(list.size() > 1)
        System.out.println(list.get(1));
        else
            System.out.println("NO");
    }
}


import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class A {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(new InputStreamReader(System.in));
		int n = s.nextInt();
		int [] ar = new int[n];
		for (int i = 0; i < n ; i++) {
			ar[i] = s.nextInt();
	 	}
		if(ar.length == 1){
			System.out.println("NO");
		}else{
			Arrays.sort(ar);
			int num = ar[0];
			boolean flag = false;
			for (int i = 1; i < ar.length; i++) {
				if(ar[i]!= num){
					System.out.println(ar[i]);
					flag = true;
					break;
				}
			}
			if(!flag)
				System.out.println("NO");
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());

		int nums[] = new int[n];
		StringTokenizer tokenizer = new StringTokenizer(in.readLine(), " ");

		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(tokenizer.nextToken());
		}

		Arrays.sort(nums);
		int min = nums[0];
		int so = -200;
		for (int i = 1; i < n; i++) {
			if(nums[i] != min) {
				so = nums[i];
				break;
			}
		}
		if(so != -200)
		System.out.println(so);
		else
			System.out.println("NO");
	}
}


import java.io.*;
import java.util.*;

public class Main implements Runnable {

	public void _main() throws IOException {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		Arrays.sort(a);
		for (int i = 1; i < n; i++)
			if (a[i] != a[0]) {
				out.print(a[i]);
				return;
			}
		out.print("NO");
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}


import static java.util.Arrays.sort;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class SecondOrderStatistics implements Runnable
{
  public static void main(String[] args) throws Exception
  {
    new SecondOrderStatistics().run();
  }

  private void solve() throws Exception
  {
    int n = nextInt();
    SortedSet<Integer> sset = new TreeSet<Integer>();
    for (int i = 0; i < n; i++)
    {
      int a = nextInt();
      sset.add(a);
    }

    if (sset.size() < 2)
      out.println("NO");
    else
    {
      Integer v[] = (Integer[]) sset.toArray(new Integer[sset.size()]);
      sort(v);
      out.println(v[1]);
    }
  }

  // -------------- Input/Output routines below ---------------//
  private BufferedReader in;
  PrintWriter out;
  StringTokenizer tokenizer;

  public void run()
  {
    // String problem = this.getClass().getName();
    try
    {
      in = new BufferedReader(new InputStreamReader(System.in));
      out = new PrintWriter(new BufferedOutputStream(System.out));
      solve();
      out.flush();
      in.close();
      out.close();
    }
    catch (Exception e)
    {
      e.printStackTrace();
      // System.exit(1);
    }
  }

  String nextToken() throws IOException
  {
    while (tokenizer == null || !tokenizer.hasMoreTokens())
    {
      tokenizer = new StringTokenizer(in.readLine());
    }
    return tokenizer.nextToken();
  }

  int nextInt() throws IOException
  {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException
  {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException
  {
    return Double.parseDouble(nextToken());
  }

}


import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    int n = s.nextInt();
	    int[] a = new int[n];
	    for(int i=0;i<n;i++)
	        a[i] = s.nextInt();
	    Arrays.sort(a);
	    int min = a[0];
	    if (a[0] == a[n-1]){
	        System.out.println("NO");
	    }else{
	        for(int i=1;;i++){
	            if (a[i] > min) {
	                System.out.println(a[i]);
	                break;
	            }
	        }
	    }
	}

}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Solution {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    void solve() throws IOException {
        int n = ni();
        int[] v = new int[n];
        for (int i = 0; i < n; ++i)
            v[i] = ni();
        Arrays.sort(v);
        int mn = v[0];
        for (int i = 1; i < n; ++i)
            if (v[i] > mn) {
                out.println(v[i]);
                return;
            }
        out.println("NO");
    }

    public Solution() throws IOException {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    String ns() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

    public static void main(String[] args) throws IOException {
        new Solution();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class A22 {

	static StreamTokenizer in;
	static PrintWriter out;

	static int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}

	static String nextString() throws IOException {
		in.nextToken();
		return in.sval;
	}

	public static void main(String[] args) throws IOException {
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out = new PrintWriter(System.out);

		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();

		Arrays.sort(a);
		int f = a[0], q = 1;
		while (q < n && a[q] == f) q++;

		out.println(q < n ? a[q] : "NO");

		out.flush();
	}

}


/**
 *
 * @author ishani
 */
import java.util.*;
public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        TreeSet<Integer> set = new TreeSet<Integer>();

        for(int i=0;i<N;i++){
            int a = sc.nextInt();
            set.add(a);
        }

        if(set.size()==1)System.out.println("NO");
        else{
            set.remove(set.first());
            System.out.println(set.first());
        }
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class CF22_1 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
    if(num!=1)
    {
        ArrayList<Integer>data=new ArrayList<Integer>();
        for (int i=0;i<num;i++){
            data.add(sc.nextInt());

        }
        Collections.sort(data);

        int ind=1;

        while( data.get(ind-1)==data.get(ind) )
            {
            ind++;
            if(ind ==data.size())
                break;
            }

        if(data.size()>ind)
        System.out.println(data.get(ind));
        else
            System.out.println("NO");

    }
    else
        System.out.println("NO");
    }

}


import java.util.*;

public class Main
{
 public static void main(String[] args)
 {
  Scanner keyboard = new Scanner(System.in);
  int size = keyboard.nextInt();
  int[] arr = new int[size];
  int i = 0;
  while( size != 0 )
  {
   arr[i] = keyboard.nextInt();
   size--;
   i++;
  }
   //System.out.print("size " + arr.length );
   Arrays.sort(arr);

   int index = 0;
   boolean val = false;
   int ans = 0;
   for ( i = 0; i< arr.length-1 ; i++ )
   {
    //System.out.print(" arr[i] " + arr[i] + " arr[i+1] " + arr[i+1] + "\n" );
    if( arr[i] != arr[i+1] )
    {
     val = true;
     //System.out.print("Changed val to true");
     index = i+1;
      System.out.println(arr[index]);
      return;
    }
   }

    if (size == 1 || ( val == false))
    {
        System.out.println("NO");
    }

 }

}


import java.io.*;
import java.util.*;

public class A {

    void run()throws IOException{
        Scanner sc = new Scanner(new InputStreamReader(System.in));
        int n = sc.nextInt();
        int i;
        int[] ar = new int[n];
        for(i=0; i<n; i++){
            ar[i] = sc.nextInt();
        }
        Arrays.sort(ar);
        int min = ar[0];
        for(i=1;i<n;i++){
            if(ar[i]>min) break;
        }
        if(i<n) System.out.println(ar[i]);
        else System.out.println("NO");
    }

    public static void main(String[] args)throws IOException {
        new A().run();
    }
}


import java.util.*;

public class Beta22PA {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int minimum = 200, second = 200;
		for(int i=0; i<n; i++) {
			int temp = scan.nextInt();
			if(temp<minimum) {
				second = minimum;
				minimum = temp;
			} else if(temp>minimum&&temp<second) {
				second = temp;
			}
		}
		if(second>100) {
			System.out.println("NO");
		} else {
			System.out.println(second);
		}
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class order {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(
				new OutputStreamWriter(System.out)));
		int n=Integer.parseInt(in.readLine());
		Set<Integer> set = new TreeSet<Integer>();
		StringTokenizer st= new StringTokenizer(in.readLine());
		int a;
		List<Integer> list =new LinkedList<Integer>();
		while(st.hasMoreTokens()){
			a= Integer.parseInt(st.nextToken());
			if(!set.contains(a)){
				list.add(a);
				set.add(a);
			}

		}
		if(list.size()==1){
			out.println("NO");
		}else{
			Collections.sort(list);
			out.println(list.get(1));
		}
		out.close();
		System.exit(0);
	}
}


import java.util.*;
import java.math.*;
/**
 *
 * @author Izhari Ishak Aksa
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Hashtable<Integer, Integer> hi = new Hashtable<Integer, Integer>();
        for (int i = 0; i < n; i++) {
            int m = sc.nextInt();
            hi.put(m, 1);
        }
        Set<Integer> set = hi.keySet();
        Integer[] key = set.toArray(new Integer[set.size()]);
        Arrays.sort(key);
        try {
            System.out.println(key[1]);
        } catch (Exception e) {
            System.out.println("NO");
        }
    }

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StreamTokenizer;
import java.lang.reflect.Array;
import java.util.Arrays;

public class a {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		//BufferedReader input = new BufferedReader(new FileReader("input.txt"));
		//BufferedWriter output = new BufferedWriter(new FileWriter("output.txt"));
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
		StreamTokenizer in = new StreamTokenizer(input);

		in.nextToken();
		int n = (int)in.nval;
		int[] mas = new int[n];

		for (int i = 0; i < n; i++) {
			in.nextToken();
			mas[i] = (int)in.nval;
		}

		Arrays.sort(mas);
		int min = mas[0];
		int i = 1;

		while ((i < n)&&(min == mas[i])) {
			i++;
		}

		if (i < n) {
			output.write(Integer.toString(mas[i]));
		}
		else {
			output.write("NO");
		}
		input.close();
		output.close();
	}

}


import java.util.*;
public class Test
{
    public static void main(String[] args)
    {
    	Scanner t = new Scanner(System.in);
    	int n=t.nextInt();
    	int a[]= new int[n];
    	for(int i=0; i<n; i++)
    		a[i]=t.nextInt();
    	Arrays.sort(a);
    	int r=a[0];
    	for(int i=1; i<n; i++)
    			if(a[i]!=r)
    			{
    				System.out.println(a[i]);
    				System.exit(0);
    			}
    	System.out.println("NO");
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package a_vtoray_poriadkovay_statistika;

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author kal1sha
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic hereSc
        int n, i;
        boolean status = false;
        int answer;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        int a[] = new int[n];
        for (i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        answer = a[0];
        for (i = 1; i < n; i++) {
            if (a[i] != answer) {
                answer = a[i];
                status = true;
                i = n + 1;
            }
        }
        if (status) {
            System.out.println(answer);
        } else {
            System.out.println("NO");
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		new A().run();
	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		int i = 0;
		while (i < n && a[i] == a[0])
			i++;
		if (i < n)
			System.out.println(a[i]);
		else
			System.out.println("NO");
		sc.close();
	}

}


//package timus;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Arrays;

public class Abra {
    public static void main(String[] args) throws IOException {
        new Abra().run();
    }

    StreamTokenizer in;
    PrintWriter out;
    boolean oj;

    void init() throws IOException {
        oj = System.getProperty("ONLINE_JUDGE") != null;
        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(
                "input.txt");
        Writer writer = oj ? new OutputStreamWriter(System.out)
                : new FileWriter("output.txt");
        // Writer writer = new OutputStreamWriter(System.out);
        in = new StreamTokenizer(new BufferedReader(reader));
        out = new PrintWriter(writer);
    }

    void run() throws IOException {
        long beginTime = System.currentTimeMillis();
        init();
        solve();
        out.flush();
    }

    void printMem() {
        if (!oj) {
            System.out.println("Memory used = "
                    + (Runtime.getRuntime().totalMemory() - Runtime
                            .getRuntime().freeMemory()));
        }
    }

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }

    long deg(long x, long y) {
        long a = x;
        for (long i = 2; i <= y; i++) {
            a *= x;
        }
        return a;
    }

    long fact(long x) {
        long a = 1;
        for (long i = 2; i <= x; i++) {
            a *= i;
        }
        return a;
    }

    long digitSum(String x) {
        long a = 0;
        for (int i = 0; i < x.length(); i++) {
            a += x.codePointAt(i) - 48;
        }
        return a;
    }

    long digitSum(long x) {
        long a = 0;
        while (x > 0) {
            a += x % 10;
            x /= 10;
        }
        return a;
    }

    long digitMul(long x) {
        long a = 1;
        while (x > 0) {
            a *= x % 10;
            x /= 10;
        }
        return a;
    }

    double pif(double ax, double ay, double bx, double by) {
        return Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
    }

    double getPosPart(double x) {
        if (x <= 0)
            return 0;
        else
            return x;
    }

    double max(double x, double y) {
        if (x > y)
            return x;
        else
            return y;
    }

    long gcd(long a, long b) {
        if (a < b) {
            long c = b;
            b = a;
            a = c;
        }
        while (a % b != 0) {
            a = a % b;
            if (a < b) {
                long c = b;
                b = a;
                a = c;
            }
        }
        return b;
    }

    int gcd(int a, int b) {
        if (a < b) {
            int c = b;
            b = a;
            a = c;
        }
        while (a % b != 0) {
            a = a % b;
            if (a < b) {
                int c = b;
                b = a;
                a = c;
            }
        }
        return b;
    }

    long lcm(long a, long b) throws IOException {
        return a * b / gcd(a, b);
    }

    int lcm(int a, int b) throws IOException {
        return a * b / gcd(a, b);
    }

    int countOccurences(String x, String y) {
        int a = 0, i = 0;
        while (true) {
            i = y.indexOf(x);
            if (i == -1)
                break;
            a++;
            y = y.substring(i + 1);
        }
        return a;
    }

    int[] primes;

    int findPrimes(int x) {
        boolean[] forErato = new boolean[x];
        primes = new int[x];
        int l = 0, j = 0;
        for (int i = 2; i < x; i++) {
            if (forErato[i])
                continue;
            l++;
            primes[l] = i;
            j = i * 2;
            while (j < x) {
                forErato[j] = true;
                j += i;
            }
        }
        return l;
    }

    int rev(int x) {
        int a = 0;
        while (x > 0) {
            a = a * 10 + x % 10;
            x /= 10;
        }
        return a;
    }

    class myDate {
        int d, m, y;

        public myDate(int da, int ma, int ya) {
            d = da;
            m = ma;
            y = ya;
        }

        int[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

        void inc() {
            if ((d == 31) && (m == 12)) {
                y++;
                d = 1;
                m = 1;
            } else {
                if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {
                    ml[1] = 29;
                }
                if (d == ml[m - 1]) {
                    m++;
                    d = 1;
                } else
                    d++;
            }
        }
    }

    int partition(int n, int l, int m) {// n - sum, l - length, m - every part
        // <= m
        if (n < l)
            return 0;
        if (n < l + 2)
            return 1;
        if (l == 1)
            return 1;
        int c = 0;
        for (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {
            c += partition(n - i, l - 1, i);
        }
        return c;
    }

    void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        int min = a[0];
        for (int i = 1; i < n; i++) {
            if (a[i] != min) {
                out.print(a[i]);
                return;
            }
        }
        out.print("NO");
    }
}