import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Locale;
import java.util.Scanner;

/**
 * @author edemairy
 */
public class Solution {

    private int nbTC;
    private StringBuilder result = new StringBuilder();

    private static class EndException extends RuntimeException {
    }

    public void run() throws IOException {
//                Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        nbTC = readInt(reader);
        nbTC = 1;//scanner.nextInt();
//         nbTC = Integer.MAX_VALUE;
//        scanner.nextLine();
        try {
            for (int tc = 1; tc <= nbTC; ++tc) {
                result.append(oneTestCase(reader));
                result.append('\n');
            }
        } catch (EndException e) {
        }
        System.out.print(result);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        Solution solution = new Solution();
        solution.run();
    }

    //    private StringBuilder oneTestCase(Scanner scanner) throws IOException {
    private StringBuilder oneTestCase(BufferedReader reader) throws IOException {
        StringBuilder output = new StringBuilder();
        int n = readInt(reader);
        Integer[] values = new Integer[n];
        for (int i=0; i<n; i++) {
            values[i] = readInt(reader);
        }
        Arrays.sort(values);
        int play = 0;
        for (int pos = 0; pos < n; pos++) {
            while ((pos < n) && (values[pos] < (play + 1))) {
                pos++;
            }
            if (pos < n) {
                play++;
            } else {
                break;
            }
        }
        output.append(play);
        return output;
    }

    private int readInt(BufferedReader reader) throws IOException {
        int r = 0;
        boolean positive = true;
        char currentChar = (char) reader.read();

        while ((currentChar == ' ') || (currentChar == '\n')) {
            currentChar = (char) reader.read();
        }
        if (currentChar == (char) -1) {
            throw new IOException("end of stream");
        }
        if (currentChar == '-') {
            positive = false;
            currentChar = (char) reader.read();
        }
        while ((currentChar >= '0') && (currentChar <= '9')) {
            r = r * 10 + currentChar - '0';
            currentChar = (char) reader.read();
        }
        if (positive) {
            return r;
        } else {
            return -r;
        }
    }

    private char readChar(BufferedReader reader) throws IOException {
        return (char) reader.read();
    }

    private int mod(int a, int b) {
        int result = a % b;
        if (result < 0) {
            result += b;
        }
        return result;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Locale;
import java.util.Scanner;

/**
 *
 * @author edemairy
 */
public class Solution {

    private int nbTC;
    private StringBuilder result = new StringBuilder();

    private static class EndException extends RuntimeException {
    }

    public void run() throws IOException {
//                Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        nbTC = readInt(reader);
nbTC = 1;//scanner.nextInt();
//         nbTC = Integer.MAX_VALUE;
//        scanner.nextLine();
        try {
            for (int tc = 1; tc <= nbTC; ++tc) {
                result.append(oneTestCase(reader));
                result.append('\n');
            }
        } catch (EndException e) {
        }
        System.out.print(result);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        Solution solution = new Solution();
        solution.run();
    }

//    private StringBuilder oneTestCase(Scanner scanner) throws IOException {
        private StringBuilder oneTestCase(BufferedReader reader) throws IOException {
        StringBuilder output = new StringBuilder();
        int n = readInt(reader);
        int[] values = new int[n];
        for (int i=0; i<n; i++) {
            values[i] = readInt(reader);
        }
        Arrays.sort(values);
        int play = 0;
        for (int i=0; i<n ; i++) {
            if (i>20000 || n>20000) {
                throw new RuntimeException();
            }
            while ((i < n) && (values[i] < (play+1))) {
                i++;
                if (i>20000 || n>20000) {
                    throw new RuntimeException();
                }
            }
            if (i<n) {
                if (i>20000 || n>20000) {
                    throw new RuntimeException();
                }
                play++;
            } else {
                if (i>20000 || n>20000) {
                    throw new RuntimeException();
                }
                break;
            }
        }
        output.append(play);
        return output;
    }

    private int readInt(BufferedReader reader) throws IOException {
        int r = 0;
        boolean positive = true;
        char currentChar = (char) reader.read();

        while ((currentChar == ' ') || (currentChar == '\n')) {
            currentChar = (char) reader.read();
        }
        if (currentChar == (char) -1) {
            throw new IOException("end of stream");
        }
        if (currentChar == '-') {
            positive = false;
            currentChar = (char) reader.read();
        }
        while ((currentChar >= '0') && (currentChar <= '9')) {
            r = r * 10 + currentChar - '0';
            currentChar = (char) reader.read();
        }
        if (positive) {
            return r;
        } else {
            return -r;
        }
    }

    private char readChar(BufferedReader reader) throws IOException {
        return (char) reader.read();
    }
    private int mod(int a, int b) {
	    int result = a %b;
	    if (result < 0) {
		    result += b;
	    }
	    return result;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Locale;
import java.util.Scanner;

/**
 *
 * @author edemairy
 */
public class Solution {

    private int nbTC;
    private StringBuilder result = new StringBuilder();

    private static class EndException extends RuntimeException {
    }

    public void run() throws IOException {
//                Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        nbTC = readInt(reader);
nbTC = 1;//scanner.nextInt();
//         nbTC = Integer.MAX_VALUE;
//        scanner.nextLine();
        try {
            for (int tc = 1; tc <= nbTC; ++tc) {
                result.append(oneTestCase(reader));
                result.append('\n');
            }
        } catch (EndException e) {
        }
        System.out.print(result);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        Solution solution = new Solution();
        solution.run();
    }

//    private StringBuilder oneTestCase(Scanner scanner) throws IOException {
        private StringBuilder oneTestCase(BufferedReader reader) throws IOException {
        StringBuilder output = new StringBuilder();
        int n = readInt(reader);
        int[] values = new int[n];
        for (int i=0; i<n; i++) {
            values[i] = readInt(reader);
        }
        Arrays.sort(values);
        int play = 0;
        for (int i=0; i<n ; i++) {
            if (i>20000) {
                throw new RuntimeException();
            }
            while ((i < n) && (values[i] < (play+1))) {
                i++;
                if (i>20000) {
                    throw new RuntimeException();
                }
            }
            if (i<n) {
                if (i>20000) {
                    throw new RuntimeException();
                }
                play++;
            } else {
                if (i>20000) {
                    throw new RuntimeException();
                }
                break;
            }
        }
        output.append(play);
        return output;
    }

    private int readInt(BufferedReader reader) throws IOException {
        int r = 0;
        boolean positive = true;
        char currentChar = (char) reader.read();

        while ((currentChar == ' ') || (currentChar == '\n')) {
            currentChar = (char) reader.read();
        }
        if (currentChar == (char) -1) {
            throw new IOException("end of stream");
        }
        if (currentChar == '-') {
            positive = false;
            currentChar = (char) reader.read();
        }
        while ((currentChar >= '0') && (currentChar <= '9')) {
            r = r * 10 + currentChar - '0';
            currentChar = (char) reader.read();
        }
        if (positive) {
            return r;
        } else {
            return -r;
        }
    }

    private char readChar(BufferedReader reader) throws IOException {
        return (char) reader.read();
    }
    private int mod(int a, int b) {
	    int result = a %b;
	    if (result < 0) {
		    result += b;
	    }
	    return result;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Locale;
import java.util.Scanner;

/**
 *
 * @author edemairy
 */
public class Solution {

    private int nbTC;
    private StringBuilder result = new StringBuilder();

    private static class EndException extends RuntimeException {
    }

    public void run() throws IOException {
//                Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        nbTC = readInt(reader);
nbTC = 1;//scanner.nextInt();
//         nbTC = Integer.MAX_VALUE;
//        scanner.nextLine();
        try {
            for (int tc = 1; tc <= nbTC; ++tc) {
                result.append(oneTestCase(reader));
                result.append('\n');
            }
        } catch (EndException e) {
        }
        System.out.print(result);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        Solution solution = new Solution();
        solution.run();
    }

//    private StringBuilder oneTestCase(Scanner scanner) throws IOException {
        private StringBuilder oneTestCase(BufferedReader reader) throws IOException {
        Formatter formatter = new Formatter(Locale.ENGLISH);
        StringBuilder output = new StringBuilder();
        int n = readInt(reader);
        int[] values = new int[n];
        for (int i=0; i<n; i++) {
            values[i] = readInt(reader);
        }
        Arrays.sort(values);
        int play = 0;
        for (int i=0; i<n ; i++) {
            while ((i < n) && (values[i] < (play+1))) {
                i++;
            }
            if (i<n) {
                play++;
                continue;
            } else {
                break;
            }
        }
        output.append(play);
        return output;
    }

    private int readInt(BufferedReader reader) throws IOException {
        int r = 0;
        boolean positive = true;
        char currentChar = (char) reader.read();

        while ((currentChar == ' ') || (currentChar == '\n')) {
            currentChar = (char) reader.read();
        }
        if (currentChar == (char) -1) {
            throw new IOException("end of stream");
        }
        if (currentChar == '-') {
            positive = false;
            currentChar = (char) reader.read();
        }
        while ((currentChar >= '0') && (currentChar <= '9')) {
            r = r * 10 + currentChar - '0';
            currentChar = (char) reader.read();
        }
        if (positive) {
            return r;
        } else {
            return -r;
        }
    }

    private char readChar(BufferedReader reader) throws IOException {
        return (char) reader.read();
    }
    private int mod(int a, int b) {
	    int result = a %b;
	    if (result < 0) {
		    result += b;
	    }
	    return result;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Locale;
import java.util.Scanner;

/**
 * @author edemairy
 */
public class Solution {

    private int nbTC;
    private StringBuilder result = new StringBuilder();

    private static class EndException extends RuntimeException {
    }

    public void run() throws IOException {
//                Scanner scanner = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        nbTC = readInt(reader);
        nbTC = 1;//scanner.nextInt();
//         nbTC = Integer.MAX_VALUE;
//        scanner.nextLine();
        try {
            for (int tc = 1; tc <= nbTC; ++tc) {
                result.append(oneTestCase(reader));
                result.append('\n');
            }
        } catch (EndException e) {
        }
        System.out.print(result);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        Solution solution = new Solution();
        solution.run();
    }

    //    private StringBuilder oneTestCase(Scanner scanner) throws IOException {
    private StringBuilder oneTestCase(BufferedReader reader) throws IOException {
        StringBuilder output = new StringBuilder();
        int n = readInt(reader);
//        Integer[] values = new Integer[n];
        int[] values = new int[n];
        for (int i=0; i<n; i++) {
            values[i] = readInt(reader);
        }
        Arrays.sort(values);
        int play = 0;
        for (int pos = 0; pos < n; pos++) {
            while ((pos < n) && (values[pos] < (play + 1))) {
                pos++;
            }
            if (pos < n) {
                play++;
            } else {
                break;
            }
        }
        output.append(play);
        return output;
    }

    private int readInt(BufferedReader reader) throws IOException {
        int r = 0;
        boolean positive = true;
        char currentChar = (char) reader.read();

        while ((currentChar == ' ') || (currentChar == '\n')) {
            currentChar = (char) reader.read();
        }
        if (currentChar == (char) -1) {
            throw new IOException("end of stream");
        }
        if (currentChar == '-') {
            positive = false;
            currentChar = (char) reader.read();
        }
        while ((currentChar >= '0') && (currentChar <= '9')) {
            r = r * 10 + currentChar - '0';
            currentChar = (char) reader.read();
        }
        if (positive) {
            return r;
        } else {
            return -r;
        }
    }

    private char readChar(BufferedReader reader) throws IOException {
        return (char) reader.read();
    }

    private int mod(int a, int b) {
        int result = a % b;
        if (result < 0) {
            result += b;
        }
        return result;
    }
}


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

public class PolycarpTraining {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		InputStreamReader read = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(read);

		int n = Integer.parseInt(in.readLine());

		String s = in.readLine();
//		String ss[] = s.split("\\s+");
		StringTokenizer st = new StringTokenizer(s);

		int arr[] = new int[n];

//		for(int i = 0 ; i < n ; i++) {
//			arr[i] = Integer.parseInt(ss[i]);
//		}

//		int i = 0 ;
		for(int i= 0  ; i < n ; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}

//
//		int n = 2*100000;
//		int arr[] = new int[n];
//
//		for(int i = 0 ; i<n ; i++) {
//			arr[i] = n-i ;
//		}
//
//		long start = System.currentTimeMillis();
		Arrays.sort(arr);

		int k = 0 ;

		int count = 0;
		int day = 0;
		while(k<n) {
			if(arr[k]>=day) {
				day++;
			}
			k++;
		}
		System.out.println(day-1);
//		long end = System.currentTimeMillis();
//		System.out.println(end-start);
	}

}


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

public class PolycarpTraining {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		InputStreamReader read = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(read);

		int n = Integer.parseInt(in.readLine());

		String s = in.readLine();
		String ss[] = s.split("\\s+");

		int arr[] = new int[n];

		for(int i = 0 ; i < n ; i++) {
			arr[i] = Integer.parseInt(ss[i]);
		}
//
//		int n = 2*100000;
//		int arr[] = new int[n];
//
//		for(int i = 0 ; i<n ; i++) {
//			arr[i] = n-i ;
//		}
//
//		long start = System.currentTimeMillis();
		Arrays.sort(arr);

		int k = 0 ;

		int count = 0;
		int day = 0;
		while(k<n) {
			if(arr[k]>=day) {
				day++;
			}
			k++;
		}
		System.out.println(day-1);
//		long end = System.currentTimeMillis();
//		System.out.println(end-start);
	}

}


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

public class PolycarpTraining {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		InputStreamReader read = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(read);

		int n = Integer.parseInt(in.readLine());

		String s = in.readLine();
		String ss[] = s.split("\\s+");

		int arr[] = new int[n+1];

		int count[] = new int[200001];

		for(int i = 1 ; i <= n ; i++) {
			arr[i] = Integer.parseInt(ss[i-1]);

			count[arr[i]]++;
		}

//		for(int i = 0 ; i <= 4 ;i++) {
//			System.out.println(count[i]);
//		}
		ArrayList<Integer> list  = new ArrayList<>();
		for(int i = 0 ; i < 200000 ; i++) {
			int c = count[i];
			while(c>0) {
				list.add(i);
				c--;
			}

		}
		int day = 1;
		for(int i = 0 ; i < list.size() ; i++) {
			if(list.get(i) >= day ) {
//				System.out.println(i+" "+day+" "+list.get(i));
				day++;
			}
		}

//		System.out.println(list);
		System.out.println(day-1);
	}

}


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

public class PolycarpTraining {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		InputStreamReader read = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(read);

		int n = Integer.parseInt(in.readLine());

		String s = in.readLine();
		String ss[] = s.split("\\s+");

		int arr[] = new int[n];

		for(int i = 0 ; i < n ; i++) {
			arr[i] = Integer.parseInt(ss[i]);
		}

		Arrays.sort(arr);

		int k = 0 ;

		int count = 0;
		int day = 0;
		while(k<n) {
			if(arr[k]>=day) {
				day++;
			}
			k++;
		}
		System.out.println(day-1);
	}

}


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

public class PolycarpTraining {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		InputStreamReader read = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(read);

		int n = Integer.parseInt(in.readLine());

		String s = in.readLine();
		String ss[] = s.split("\\s+");

		int arr[] = new int[n+1];

		int count[] = new int[200001];

		for(int i = 1 ; i <= n ; i++) {
			arr[i] = Integer.parseInt(ss[i-1]);

			count[arr[i]]++;
		}

//		for(int i = 0 ; i <= 4 ;i++) {
//			System.out.println(count[i]);
//		}
		ArrayList<Integer> list  = new ArrayList<>();
		for(int i = 0 ; i <= 200000 ; i++) {
			int c = count[i];
			while(c>0) {
				list.add(i);
				c--;
			}

		}
		int day = 1;
		for(int i = 0 ; i < list.size() ; i++) {
			if(list.get(i) >= day ) {
//				System.out.println(i+" "+day+" "+list.get(i));
				day++;
			}
		}

//		System.out.println(list);
		System.out.println(day-1);
	}

}


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

public class PolycarpTraining {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		InputStreamReader read = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(read);

		int n = Integer.parseInt(in.readLine());

		String s = in.readLine();
		String ss[] = s.split("\\s+");

		int arr[] = new int[n];

		for(int i = 0 ; i < n ; i++) {
			arr[i] = Integer.parseInt(ss[i]);
		}

		Arrays.sort(arr);

		int k = 0 ;

		int count = 0;
		int day = 0;
		while(k<n) {
			if(arr[k]>=day) {
				day++;
			}
			k++;
		}
		System.out.println(day-1);
	}

}


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

public class CF_1110 {

     public static void main(String[] args) throws IOException{
        FastReader scn = new FastReader() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int n = scn.nextInt() ;
        int[] a = new int[n] ;
        for(int i = 0; i < n; i ++){
            a[i] = scn.nextInt() ;
        }
        Arrays.sort(a) ;
        int j = 1 ;
        for(int i = 0 ; i < n ; i++){
            if(a[i] >= j){
                j++;
            }
        }
       System.out.println(j - 1);
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
     static class FastReader
     {
         BufferedReader br;
         StringTokenizer st;

         public FastReader()
         {
             br = new BufferedReader(new
                      InputStreamReader(System.in));
         }

         String next()
         {
             while (st == null || !st.hasMoreElements())
             {
                 try
                 {
                     st = new StringTokenizer(br.readLine());
                 }
                 catch (IOException  e)
                 {
                     e.printStackTrace();
                 }
             }
             return st.nextToken();
         }

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

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

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

         String nextLine()
         {
             String str = "";
             try
             {
                 str = br.readLine();
             }
             catch (IOException e)
             {
                 e.printStackTrace();
             }
             return str;
         }
     }

 }


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

public class CF_1110 {

    public static void main(String[] args) throws IOException{
        FastScanner scn = new FastScanner() ;
        int n = scn.nextInt() ;
        int[] arr = new int[n] ;
        for(int i = 0; i < n ; i++){
            arr[i] = scn.nextInt() ;
        }
        Arrays.sort(arr);
        int k = 1 ;
        for(int i = 0; i < n ;i++){
            if(arr[i] >= k){
                k++ ;
            }
        }
        System.out.println(k - 1);
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

 }


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

public class CF_1110 {

    public static void main(String[] args) throws IOException{
        FastReader scn = new FastReader() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int n = scn.nextInt() ;
        int[] arr = new int[n] ;
        for(int i = 0; i < n; i ++){
            arr[i] = scn.nextInt() ;
        }
        Arrays.sort(arr) ;
        int j = 1 ;
        for(int i = 0 ; i < n ; i++){
            if(arr[i] >= j){
                j++;
            }
        }
       out.write("" + (j - 1) + "\n");
       out.flush();
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
     static class FastReader
     {
         BufferedReader br;
         StringTokenizer st;

         public FastReader()
         {
             br = new BufferedReader(new
                      InputStreamReader(System.in));
         }

         String next()
         {
             while (st == null || !st.hasMoreElements())
             {
                 try
                 {
                     st = new StringTokenizer(br.readLine());
                 }
                 catch (IOException  e)
                 {
                     e.printStackTrace();
                 }
             }
             return st.nextToken();
         }

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

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

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

         String nextLine()
         {
             String str = "";
             try
             {
                 str = br.readLine();
             }
             catch (IOException e)
             {
                 e.printStackTrace();
             }
             return str;
         }
     }

 }


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

public class CF_1110 {

     public static void main(String[] args) throws IOException{
        FastReader scn = new FastReader() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int n = scn.nextInt() ;
        int[] arr = new int[n] ;
        for(int i = 0; i < n; i ++){
            arr[i] = scn.nextInt() ;
        }
        Arrays.sort(arr) ;
        int j = 1 ;
        for(int i = 0 ; i < n ; i++){
            if(arr[i] >= j){
                j++;
            }
        }
       out.write("" + (j - 1) + "\n");
       out.flush();
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
     static class FastReader
     {
         BufferedReader br;
         StringTokenizer st;

         public FastReader()
         {
             br = new BufferedReader(new
                      InputStreamReader(System.in));
         }

         String next()
         {
             while (st == null || !st.hasMoreElements())
             {
                 try
                 {
                     st = new StringTokenizer(br.readLine());
                 }
                 catch (IOException  e)
                 {
                     e.printStackTrace();
                 }
             }
             return st.nextToken();
         }

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

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

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

         String nextLine()
         {
             String str = "";
             try
             {
                 str = br.readLine();
             }
             catch (IOException e)
             {
                 e.printStackTrace();
             }
             return str;
         }
     }

 }


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

public class CF_1110 {

    public static void main(String[] args) throws IOException{
        FastScanner scn = new FastScanner() ;
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)) ;
        int n = scn.nextInt() ;
        int[] arr = new int[n] ;
        for(int i = 0; i < n; i ++){
            arr[i] = scn.nextInt() ;
        }
        Arrays.sort(arr) ;
        int j = 1 ;
        for(int i = 0 ; i < n ; i++){
            if(arr[i] >= j){
                j++;
            }
        }
       out.write("" + (j - 1) + "\n");
       out.flush();
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

 }


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

public class CF_1110 {

    public static void main(String[] args) throws IOException{
        FastScanner scn = new FastScanner() ;
        int n = scn.nextInt() ;
        int[] arr = new int[n] ;
        for(int i = 0; i < n; i ++){
            arr[i] = scn.nextInt() ;
        }
        Arrays.sort(arr) ;
        int j = 1 ;
        for(int i = 0 ; i < n ; i++){
            if(arr[i] >= j){
                j++;
            }
        }
       System.out.println(j - 1);
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

 }


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

public class CF_1110 {

    public static void main(String[] args) throws IOException{
        FastScanner scn = new FastScanner() ;
        int n = scn.nextInt() ;
        Vector<Integer> arr = new Vector<>() ;
        for(int i = 0; i < n ; i++){
            arr.add(scn.nextInt()) ;
        }
        Collections.sort(arr);
        int k = 1 ;
        for(int i = 0; i < n ;i++){
            if(arr.get(i) >= k){
                k++ ;
            }
        }
        System.out.println(k - 1);
     }

     static class Pair {
        long f ;
        int s ;
        Pair(long f , int s){
            this.f = f ;
            this.s = s ;
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

 }


import java.util.*;

public class Question1165B {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        Set<Integer> set=new HashSet<>();
        for(int i=0;i<n;i++){
            set.add(sc.nextInt());
        }
        long c=0;
        for(int i=1;i<=n;i++){
            if(set.contains(i)){
                c++;
            }
        }
        System.out.println(c);

    }
}


import java.util.*;

public class Question1165B {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<n;i++){
            list.add(sc.nextInt());
        }
        Collections.sort(list);

        int i=1;

        for(int j=0;j<n;j++){
            if(list.get(j)>=i){
                i++;
            }
        }
System.out.println(i-1);
    }
}


import java.util.*;

public class Question1165B {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=sc.nextInt();
        }
        Arrays.sort(arr);

        int i=1;
        for(int j=0;j<arr.length;j++){
            if(arr[j]>=i){
                i++;
            }
        }
System.out.println(--i);
    }
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Question1165B {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<n;i++){
            list.add(sc.nextInt());
        }
        int c=0;
        for(int i=1;i<=n;i++){
            if(list.contains(i)){
                c++;
            }
        }
        System.out.println(c);

    }
}


import java.util.*;

public class Question1165B {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=sc.nextInt();
        }
        Arrays.sort(arr);

        int i=1;
        for(int j=0;j<n;j++){
            if(arr[j]>=i){
                i++;
            }
        }
System.out.println(i-1);
    }
}


import java.util.*;
public class polycarpsTraining {
    public static void main(String[] args) {
        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();
        }
        int c=1;
        Arrays.sort(a);
        for(int i=0;i<n;i++)
        {
            if(a[i]>=c)
            {
                c++;
            }

        }
        System.out.println(c-1);
    }
}


import java.util.*;
public class polycarpsTraining {
    public static void main(String[] args) {
        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();
        }
        int c=0;
        Arrays.sort(a);
        for(int i=0;i<n;i++)
        {
            if(a[i]>=(i+1))
            {
                c++;
            }

        }
        System.out.println(c);
    }
}


import java.util.*;
public class polycarpsTraining {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        TreeSet<Integer> hs=new TreeSet<>();
       int k=1;
       int x=0;
       for(int i=0;i<n;i++)
           hs.add(sc.nextInt());
      for(Integer it:hs)
      {
          //System.out.println(it);
          if(it>=k)
          {
              k++;
              x++;
          }
          else
          {
             // System.out.println(x);
              break;
          }
      }
        System.out.println(x);
    }
}


import java.util.*;
public class msol{
	public static void main(String s[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		for(int i=0;i<n;i++)
			al.add(sc.nextInt());
		Collections.sort(al);
		int day=1;
		int count=0;
		for(int i=0;i<n;i++){
			if(al.get(i)>=day){
				count++;
				day++;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
public class polycarpsTraining {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        TreeSet<Integer> hs=new TreeSet<>();
        for(int i=0;i<n;i++)
        {
            hs.add(sc.nextInt());
        }
        System.out.println(hs.size());
    }
}


//package Round560;

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

public class typeB {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;
		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				train++;
				k++;
				continue;
			}
			else {
				continue;
			}
		}
		System.out.println(train);
	}
}


//package Round560;

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

public class typeB {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	 int binarySearch(int arr[], int l, int r, int x)
	    {
	        if (r >= l) {
	            int mid = l + (r - l) / 2;

	            // If the element is present at the
	            // middle itself
	            if (arr[mid] == x)
	                return mid;

	            // If element is smaller than mid, then
	            // it can only be present in left subarray
	            if (arr[mid] > x)
	                return binarySearch(arr, l, mid - 1, x);

	            // Else the element can only be present
	            // in right subarray
	            return binarySearch(arr, mid + 1, r, x);
	        }

	        // We reach here when element is not present
	        // in array
	        return -1;
	    }
	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				train++;
				k++;
			}
		}
		System.out.println(train);
	}
}


//package Round560;

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

public class typeB {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	 int binarySearch(int arr[], int l, int r, int x)
	    {
	        if (r >= l) {
	            int mid = l + (r - l) / 2;

	            // If the element is present at the
	            // middle itself
	            if (arr[mid] == x)
	                return mid;

	            // If element is smaller than mid, then
	            // it can only be present in left subarray
	            if (arr[mid] > x)
	                return binarySearch(arr, l, mid - 1, x);

	            // Else the element can only be present
	            // in right subarray
	            return binarySearch(arr, mid + 1, r, x);
	        }

	        // We reach here when element is not present
	        // in array
	        return -1;
	    }
	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				train++;
				k++;
			}
			else {
			}
		}
		System.out.println(train);
	}
}


//ackage Round560;

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

public class typeB {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				//train++;
				k++;
			}
		}
		System.out.println(k-1);
	}
}


package Round560;

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

public class typeB {
//	static class FastReader
//    {
//        BufferedReader br;
//        StringTokenizer st;
//
//        public FastReader()
//        {
//            br = new BufferedReader(new
//                     InputStreamReader(System.in));
//        }
//
//        String next()
//        {
//            while (st == null || !st.hasMoreElements())
//            {
//                try
//                {
//                    st = new StringTokenizer(br.readLine());
//                }
//                catch (IOException  e)
//                {
//                    e.printStackTrace();
//                }
//            }
//            return st.nextToken();
//        }
//
//        int nextInt()
//        {
//            return Integer.parseInt(next());
//        }
//
//        long nextLong()
//        {
//            return Long.parseLong(next());
//        }
//
//        double nextDouble()
//        {
//            return Double.parseDouble(next());
//        }
//
//        String nextLine()
//        {
//            String str = "";
//            try
//            {
//                str = br.readLine();
//            }
//            catch (IOException e)
//            {
//                e.printStackTrace();
//            }
//            return str;
//        }
//    }
//
	public static void main(String[] args) {
		//FastReader s = new FastReader();
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				train++;
				k++;
			}
		}
		System.out.println(train);
	}
}


//package Round560;

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

public class typeB {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		FastReader s = new FastReader();
		int n = s.nextInt();
		Integer[] arr = new Integer[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				//train++;
				k++;
			}
		}
		System.out.println(k-1);
	}
}


//package Round560;

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

public class typeB {
//	static class FastReader
//    {
//        BufferedReader br;
//        StringTokenizer st;
//
//        public FastReader()
//        {
//            br = new BufferedReader(new
//                     InputStreamReader(System.in));
//        }
//
//        String next()
//        {
//            while (st == null || !st.hasMoreElements())
//            {
//                try
//                {
//                    st = new StringTokenizer(br.readLine());
//                }
//                catch (IOException  e)
//                {
//                    e.printStackTrace();
//                }
//            }
//            return st.nextToken();
//        }
//
//        int nextInt()
//        {
//            return Integer.parseInt(next());
//        }
//
//        long nextLong()
//        {
//            return Long.parseLong(next());
//        }
//
//        double nextDouble()
//        {
//            return Double.parseDouble(next());
//        }
//
//        String nextLine()
//        {
//            String str = "";
//            try
//            {
//                str = br.readLine();
//            }
//            catch (IOException e)
//            {
//                e.printStackTrace();
//            }
//            return str;
//        }
//    }
//
	public static void main(String[] args) {
		//FastReader s = new FastReader();
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				train++;
				k++;
			}
		}
		System.out.println(train);
	}
}


//package Round560;

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

public class typeB {
//	static class FastReader
//    {
//        BufferedReader br;
//        StringTokenizer st;
//
//        public FastReader()
//        {
//            br = new BufferedReader(new
//                     InputStreamReader(System.in));
//        }
//
//        String next()
//        {
//            while (st == null || !st.hasMoreElements())
//            {
//                try
//                {
//                    st = new StringTokenizer(br.readLine());
//                }
//                catch (IOException  e)
//                {
//                    e.printStackTrace();
//                }
//            }
//            return st.nextToken();
//        }
//
//        int nextInt()
//        {
//            return Integer.parseInt(next());
//        }
//
//        long nextLong()
//        {
//            return Long.parseLong(next());
//        }
//
//        double nextDouble()
//        {
//            return Double.parseDouble(next());
//        }
//
//        String nextLine()
//        {
//            String str = "";
//            try
//            {
//                str = br.readLine();
//            }
//            catch (IOException e)
//            {
//                e.printStackTrace();
//            }
//            return str;
//        }
//    }
//
	public static void main(String[] args) {
		FastReader s = new FastReader();
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		Arrays.sort(arr);
		int k=1;
		int train=0;

		for(int i=0;i<arr.length;i++) {
			if(arr[i]>=k) {
				train++;
				k++;
			}
		}
		System.out.println(train);
	}
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		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 k=1;
		for(int i=0;i<n;i++){
			if(a[i]>k) k++;
		}
		System.out.println(k);
	}
}


package main;

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int k=1;
		for(int i=0;i<n;i++){
			if(a[i]<k) continue;
			else k++;
		}
		System.out.println(k-1);
	}
}


package main;

import java.util.*;
public class Main {
	public static void main(String[] args){
		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 k=1;
		for(int i=0;i<n;i++){
			if(a[i]>k) k++;
		}
		System.out.println(k);
	}
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int k=1;
		for(int i=0;i<n;i++){
			if(a[i]>k) k++;
		}
		System.out.println(k);
	}
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int k=1;
		for(int i=0;i<n;i++){
			if(a[i]<k) continue;
			else k++;
		}
		System.out.println(k-1);
	}
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		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 k=1;
		for(int i=0;i<n;i++){
			 if(a[i]<k) continue; // 如果这场比赛比当前天数的需求量小，那么一定不会被选择到了。
		     else k++;
		}
		System.out.println(k-1);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Task2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        int[] first = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        Arrays.sort(first);
        int k=0;
        for(int i=1; i<=n; i++){
            if (first[i-1]>k){
                k++;
            }
        }
        System.out.println(k);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Task2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] s=reader.readLine().split(" ");
        Arrays.sort(s);
        int k=1;
        for(int i=1; i<=n; i++){
            if (Integer.parseInt(s[i-1])>=k){
                k++;
            }
        }
        System.out.println(k-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Task2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        int[] first = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        Arrays.sort(first);
        int k=0;
        for(int i=1; i<=n; i++){
            if (first[i-1]>=k){
                k++;
            }
        }
        System.out.println(k);
    }
}


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

public class Task2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        int[] first = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        Arrays.sort(first);
        int k=1;
        int t=0;
        for(int x:first){
            if(x>=k){
                k++;
                t++;
            }
        }
        System.out.println(t);
    }
}


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

public class Task2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Integer[] sa = new Integer[n];
        for(int i=0; i<n; i++){
            sa[i] = scan.nextInt();
        }

        Arrays.sort(sa);
        int k=1;
        for(int i=1; i<=n; i++){
            if (sa[i-1]>=k){
                k++;
            }
        }
        System.out.println(k-1);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Task2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] s=reader.readLine().split(" ");
        Arrays.sort(s);
        Set<String> ki=new HashSet<>();
        int k=0;
        for(int i=1; i<=n; i++){
            if(Integer.parseInt(s[i-1])>=k && !ki.contains(s[i-1])){
                k++;
                ki.add(s[i-1]);
            }
        }
        System.out.println(k);
    }
}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int arr[] = new int[N];
		for(int i = 0; i < N; i++) {
			arr[i] = N;
		}
		Arrays.sort(arr);
		int sum = 0;
		for(int i = 1; i < N; i++) {
			if(arr[i] > arr[i-1]) {
				sum++;
			}
		}
		System.out.println(sum);
		in.close();
	}

}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int arr[] = new int[N];
		for(int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int sum = 1;
		for (int i = 0, j = 1; i <  N &&j <= N;i++){
			if(arr[i] >= j){
				sum++;
				j++;
	         }
		}
		System.out.println(sum);
		in.close();
	}
}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Set<Integer> list = new LinkedHashSet<>();
		int N = in.nextInt();
		for(int i = 0; i < N; i++) {
			list.add(in.nextInt());
		}
		in.close();
		System.out.println(list.size());
	}

}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int arr[] = new int[N];
		for(int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int sum = 0;
		for (int i = 0, j = 1; i <  N &&j <= N;i++){
			if(arr[i] >= j){
				sum++;
				j++;
	         }
		}
		System.out.println(sum);
		in.close();
	}
}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int arr[] = new int[N];
		for(int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int sum = 1;
		for(int i = 1; i < N; i++) {
			if(arr[i] > arr[i-1]) {
				sum++;
			}
		}
		System.out.println(sum);
		in.close();
	}

}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int arr[] = new int[N];
		for(int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int sum = 1;
		for (int i = 1, j = 1; i <=  N &&j <= N;)
		{
			if(arr[i] >= j)
	         {
				sum++;
				i++;
				j++;
			}
	        else
	        {
		        i++;
	        }
		System.out.println(sum);
		in.close();
		}
	}
}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        int n = in.nextInt(), curr = 1;
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = in.nextInt();
        in.close();
        Arrays.sort(a);
        for(int i = 0; i < n; i++) if(curr <= a[i]) curr++;
        System.out.println(curr-1);
	}
}


import java.util.*;

public class Polycarp {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        int n = in.nextInt(), curr = 1;
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = in.nextInt();
        in.close();
        Arrays.sort(a);
        for(int i = 0; i < n; i++) if(curr <= a[i]) curr++;
        System.out.println(curr-1);
	}
}


import java.util.*;
public class remainder {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner s=new Scanner(System.in);

		int n=s.nextInt();
		int x=s.nextInt();
		int y=s.nextInt();

		String str=s.next();

		int check=0;

		for(int i=n-x,k=0;i<n;i++,k++)
		{
			if(k==x-y-1)
			{
				check+= str.charAt(i)=='1' ? 0 : 1;
			}
			else
			{
				check+= str.charAt(i)=='1' ? 1 : 0;
			}

		}

		System.out.println(check);
	}

}


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

public class polycarpTraining {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		FastReader s=new FastReader();

		int n=s.nextInt();

		int ar[]=new int[n];

		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();

		Arrays.sort(ar);

		int solve=1;

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

			if(ar[i]>=solve)
				solve++;
		}

		System.out.println(solve-1);

	}

}


import java.util.*;
public class polycarpTraining {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner s=new Scanner(System.in);

		int n=s.nextInt();

		int ar[]=new int[n];

		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();

		Arrays.sort(ar);

		int solve=1;

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

			while(i<n && ar[i]<solve)
				i++;

			if(i==n)
				break;

			if(ar[i]>=solve) {

			//	System.out.println(ar[i]+" "+solve);
				solve++;
			}
		}

		System.out.println(solve-1);

	}

}


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

public class polycarpTraining {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		FastReader s=new FastReader();

		int n=s.nextInt();

		ArrayList<Integer> ar=new ArrayList<>();

		for(int i=0;i<n;i++)
			ar.add(s.nextInt());

		Collections.sort(ar);

		int solve=1;

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

			if(ar.get(i)>=solve)
				solve++;
		}

		System.out.println(solve-1);

	}

}


import java.util.*;
public class polycarpTraining {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner s=new Scanner(System.in);

		int n=s.nextInt();

		int ar[]=new int[n];

		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();

		Arrays.sort(ar);

		int solve=1;

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

			if(ar[i]>=solve)
				solve++;
		}

		System.out.println(solve-1);

	}

}


import java.util.*;

public class Solution{
    static Scanner scan = new Scanner(System.in);
    static int array[] = new int[200009];

    public static void main(String args[]){
        int n = scan.nextInt();
        int sorted[] = new int[n];

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

        int k = 0;
        for(int i = 0; i < array.length; i++){
            for(int j = 0; j < array[i]; j++){
                sorted[k++] = i;
            }
        }

        long no = 1;
        for(int i = 0; i < n; i++){
            if(sorted[i] >= no){
                no++;
            }
        }

        System.out.println(no-1);
    }

}


import java.util.*;

public class Solution{
    static Scanner scan = new Scanner(System.in);

    public static void main(String args[]){
        int n = scan.nextInt();
        int array[] = new int[n];

        for(int i = 0; i < n; i++){
            array[i] = scan.nextInt();
        }
        Arrays.sort(array);

        int no = 1;
        for(int i = 0; i < n; i++){
            if(array[i] >= no){
                no++;
            }
        }

        System.out.println(no-1);
    }

}


import java.util.*;

public class Solution{
    static Scanner scan = new Scanner(System.in);

    public static void main(String args[]){
        int n = scan.nextInt();
        long array[] = new long[n];

        for(int i = 0; i < n; i++){
            array[i] = scan.nextLong();
        }
        Arrays.sort(array);

        long no = 1;
        for(int i = 0; i < n; i++){
            if(array[i] >= no){
                no++;
            }
        }

        System.out.println(no-1);
    }

}


import java.util.*;

public class Solution{
    static Scanner scan = new Scanner(System.in);
    static int array[] = new int[200005];

    public static void main(String args[]){
        int n = scan.nextInt();

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

        long no = 0;
        for(int i = 1; i <= n; i++){
            if(array[i] >= 1){
                no++;
            }
        }

        System.out.println(no);
    }

}


import java.util.*;

public class Solution{
    static Scanner scan = new Scanner(System.in);
    static Set<Integer> set = new HashSet<Integer>();

    public static void main(String args[]){
        int n = scan.nextInt();

        while(n-- > 0){
            int input = scan.nextInt();
            set.add(input);
        }

        System.out.println(set.size());
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class cf1 {
    public static void main(String[] args) throws Exception{
        MScanner sc = new MScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        int[]in=new int[n];
        for(int i=0;i<n;i++) {
        	in[i]=sc.nextInt();
        }
        Arrays.sort(in);
        int i=0;int d=0;
        while(i<n) {
        	while(i<n && in[i]<=d) {
        		i++;
        	}
        	if(i<n) {
        		i++;d++;
        	}
        }
        pw.print(d);
        pw.flush();
    }

    static class MScanner {
        StringTokenizer st;
        BufferedReader br;

        public MScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class cf1 {
    public static void main(String[] args) throws Exception{
        MScanner sc = new MScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        PriorityQueue<Integer>in=new PriorityQueue<Integer>();
        for(int i=0;i<n;i++) {
        	in.add(sc.nextInt());
        }
        int d=0;
        while(!in.isEmpty()) {
        	if(in.poll()>d) {
        		d++;
        	}

        }
        pw.print(d);
        pw.flush();
    }

    static class MScanner {
        StringTokenizer st;
        BufferedReader br;

        public MScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class cf1 {
    public static void main(String[] args) throws Exception{
        MScanner sc = new MScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        Integer[]in=new Integer[n];
        for(int i=0;i<n;i++) {
        	in[i]=sc.nextInt();
        }
        Arrays.sort(in);
        int i=0;int d=0;
        while(i<n) {
        	if(in[i]>d) {
        		d++;
        	}
        	i++;
        }
        pw.print(d);
        pw.flush();
    }

    static class MScanner {
        StringTokenizer st;
        BufferedReader br;

        public MScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class cf1 {
    public static void main(String[] args) throws Exception{
        MScanner sc = new MScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        int[]in=new int[n];
        for(int i=0;i<n;i++) {
        	in[i]=sc.nextInt();
        }
        Arrays.sort(in);
        int i=0;int d=0;
        while(i<n) {
        	if(in[i]>d) {
        		d++;
        	}
        	i++;
        }
        pw.print(d);
        pw.flush();
    }

    static class MScanner {
        StringTokenizer st;
        BufferedReader br;

        public MScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <bitset>

#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y0 ywuerosdfhgjkls
#define y1 hdsfjkhgjlsdfhgsdf
#define j1 j924
#define j0 j2834
#define sqrt(x) (sqrt(abs(x)))
#define re return
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = ((n) - 1); i >= 0; i--)
#define fill(a, x) memset(a, x, sizeof(a))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;
typedef double D;
typedef vector <string> vs;

template <class T> inline T abs(T a) {
    return a > 0 ? a : -a;
}

int n;

unsigned short int dp[512][100000];
unsigned short int dp2[512][50000];

int ed[100000];
int s[50000];

vi g[50000];

int cnt = 0;

int debug = 0;

int calc(int, int);
int gom(int, int);

int gom(int u, int k) {

    unsigned short &ans = dp2[k][u];
    if (ans < n + 1)
        re ans;
    cnt++;
    if (k == 0)
        re ans = 1;
    ans = 0;
    rep(i, sz(g[u])) {
        ans += calc(g[u][i], k - 1);
    }
    re ans;
}

int calc(int e, int k) {
    unsigned short &ans = dp[k][e];
    if (ans < n + 1)
        re ans;
    cnt++;
    if (k == 0)
        re ans = 1;
    ans = 0;
    int u = ed[e];
    ans = dp2[k][u] - calc(e ^ 1, k - 1);
    re ans;
}

int main() {
    int k;
    scanf("%d%d", &n, &k);
    //n = 50000;
    //k = 500;
    int m = 0;
    rep(i, n - 1) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--; v--;
        ed[m] = v;
        g[u].pb(m);
        m++;

        ed[m] = u;
        g[v].pb(m);
        m++;
    }
    fill(dp, 0);
    fill(dp2, 0);
    rep(j, k + 1) {
        rep(u, n) {
            if (j == 0) {
                dp2[j][u] = 1;
                continue;
            }
            rep(i, sz(g[u])) {
                dp2[j][u] += dp[j - 1][g[u][i]];
            }
        }
        rep(e, m) {
            if (j == 0) {
                dp[j][e] = 1;
                continue;
            }
            int u = ed[e];
            dp[j][e] = dp2[j][u] - dp[j - 1][e ^ 1];
        }
    }
    ll ans = 0;
    rep(i, n) {
        ans += dp2[k][i];
    }
    //cerr << cnt << ' ' << cnt / n / k << endl;
    cout << ans / 2 << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <bitset>

#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y0 ywuerosdfhgjkls
#define y1 hdsfjkhgjlsdfhgsdf
#define j1 j924
#define j0 j2834
#define sqrt(x) (sqrt(abs(x)))
#define re return
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = ((n) - 1); i >= 0; i--)
#define fill(a, x) memset(a, x, sizeof(a))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;
typedef double D;
typedef vector <string> vs;

template <class T> inline T abs(T a) {
    return a > 0 ? a : -a;
}

int n;

unsigned short dp[100000][500];

int ed[100000];
int s[50000];

vi g[50000];

int cnt = 0;

int calc(int e, int k) {

    //if (k == 0)
    //  re 1;
    if (dp[e][k] < n + 1)
        re dp[e][k];
    cnt++;
    unsigned short &ans = dp[e][k];
    ans = 0;
    int u = ed[e];
    rep(i, sz(g[u])) {
        int ee = g[u][i];
        if ((ee ^ e) != 1) {
            if (k != 1)
                ans += calc(ee, k - 1);
            else
                ans++;
        }
    }
    re ans;
}

int main() {
    int k;
    scanf("%d%d", &n, &k);
    //n = 50000;
    //k = 500;
    int m = 0;
    rep(i, n - 1) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--; v--;
        ed[m] = v;
        g[u].pb(m);
        m++;

        ed[m] = u;
        g[v].pb(m);
        m++;
    }
    rep(i, n)
        s[i] = sz(g[i]);
    ll ans = 0;
    fill(dp, 255);
    rep(i, n) {
        rep(j, sz(g[i])) {
            ans += calc(g[i][j], k - 1);
        }
    }
    cerr << cnt << endl;
    cout << ans / 2 << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b) for(int a = (b); a; a = o[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], w[N + N], p;
int c, d[N], g;
LL A;
bool r[N];

struct odp{
	int d, g;
	odp(){}
	odp(int d, int g) : d(d), g(g){}
	bool operator < (const odp &T) const{ return d != T.d ? d < T.d : g < T.g;}
} b[N];

void bd(int a, int b){
	v[++p] = b; o[p] = f[a]; f[a] = p;
}

void cent(int x, int p, int s){
	int m = 0;
	d[x] = 1;
	fe(i, f[x]) if(v[i] != p && !r[v[i]]){
		cent(v[i], x, s);
		m = max(m, d[v[i]]);
		d[x] += d[v[i]];
	}

	m = max(m, s - d[x]);
	if(m < c){
		c = m;
		g = x;
	}
}

int size(int x, int p){
	int e = 1;
	fe(i, f[x]) if(v[i] != p && !r[v[i]])
		e += size(v[i], x);
	return e;
}

void dfs(int x, int p, int s, int d){
	b[c++] = odp(d, s);
	fe(i, f[x]) if(v[i] != p && !r[v[i]])
		dfs(v[i], x, s, d + 1);
}

void root(int x){
	int s = 0;
	c = d[x] = 0;
	b[c++] = odp(0, s++);
	r[x] = 1;

	fe(i, f[x]) if(!r[v[i]])
		dfs(v[i], x, s++, 1);

	sort(b, b + c);

	fi(i, 0, s) d[i] = 0;
	fi(i, 0, c) d[b[i].g]++;
	for(int i = 0, j = c - 1; i < j; i++){
		d[b[i].g]--;
		while(i < j && b[i].d + b[j].d > k){
			d[b[j].g]--;
			j--;
		}

		A += j - i - d[b[i].g];
	}

	fi(i, 0, s) d[i] = 0;
	fi(i, 0, c) d[b[i].g]++;
	for(int i = 0, j = c - 1; i < j; i++){
		d[b[i].g]--;
		while(i < j && b[i].d + b[j].d >= k){
			d[b[j].g]--;
			j--;
		}

		A -= j - i - d[b[i].g];
	}

	fe(i, f[x]) if(!r[v[i]]){
		c = 1 << 30;
		cent(v[i], x, size(v[i], x));
		root(g);
	}
}

int main(){
	scanf("%d %d", &n, &k);
	A = p = 0;
	FI(i, 1, n) f[i] = r[i] = 0;
	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}
	root(1);
	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, s[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p){
	s[x] = 1;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]]){
		dfs(v[i], x);
		s[x] += s[v[i]];
	}

	l[t++] = x;
}

void bfs(int x, int p, int q){
	if(q > k || r[x]) return;

	A += c[k - q];
	fe(i, f[x], o) if(v[i] != p)
		bfs(v[i], x, q + 1);

	c[q]++;
	l[t++] = q;
}

void root(int x){
	a = 1 << 29;
	t = 0;
	dfs(x, 0);

	fi(i, 0, t){
		int y = l[i], m = s[x] - s[y];

		fe(j, f[y], o) if(!r[v[j]] && s[v[j]] < s[y])
			m = max(m, s[v[j]]);

		if(m < a) a = m, b = y;
	}

	t = 0;
	fe(i, f[b], o) bfs(v[i], b, 1);
	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) if(!r[v[i]]) root(v[i]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1);

	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, s[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p){
	s[x] = 1;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]]){
		dfs(v[i], x);
		s[x] += s[v[i]];
	}

	l[t++] = x;
}

void bfs(int x, int p, int q){
	if(q > k) return;

	A += c[k - q];
	fe(i, f[x], o) if(v[i] != p && !r[v[i]])
		bfs(v[i], x, q + 1);

	c[q]++;
	l[t++] = q;
}

void root(int x){
	a = 1 << 29;
	t = 0;
	dfs(x, 0);

	fi(i, 0, t){
		int y = l[i], m = s[x] - s[y];

		fe(j, f[y], o) if(!r[v[j]] && s[v[j]] < s[y])
			m = max(m, s[v[j]]);

		if(m < a) a = m, b = y;
	}

	t = 0;
	fe(i, f[b], o) if(!r[v[i]]) bfs(v[i], b, 1);
	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) if(!r[v[i]]) root(v[i]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1);

	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, s[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p){
	s[x] = 1;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]]){
		dfs(v[i], x);
		s[x] += s[v[i]];
	}

	l[t++] = x;
}

void bfs(int x, int p, int q){
	if(q > k) return;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]])
		bfs(v[i], x, q + 1);
	l[t++] = q;
}

void root(int x){
	a = 1 << 29;
	t = 0;
	dfs(x, 0);

	fi(i, 0, t){
		int y = l[i], m = s[x] - s[y];

		fe(j, f[y], o) if(!r[v[j]] && s[v[j]] < s[y])
			m = max(m, s[v[j]]);

		if(m < a) a = m, b = y;
	}

	t = 0;
	fe(i, f[b], o) if(!r[v[i]]){
		int T = t;
		bfs(v[i], b, 1);

		fi(i, T, t) A += c[k - l[i]];
		fi(i, T, t) c[l[i]]++;
	}
	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) if(!r[v[i]]) root(v[i]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1);

	printf("%I64d\n", A);
	scanf("\n");
}


#include <cstdio>
#include <algorithm>
#define N 50005
#define M 100050
#define K 505
#define FI(a, b, c) for(int a = b; a <= c; a++)
#define FD(a, b, c) for(int a = b; a >= c; a--)
using namespace std;

typedef long long LL;

int n, k, f[N], v[M], o[M], d[N][K];
LL A;

void dfs(int V, int p){
	d[V][0] = 1;
	for(int i = f[V]; i; i = o[i]) if(v[i] != p){
		dfs(v[i], V);
		FI(j, 0, k - 1)
			A += (LL) d[V][j] * d[v[i]][k - j - 1];
		FI(j, 1, k)
			d[V][j] += d[v[i]][j - 1];
	}
}

int main(){
	scanf("%d %d", &n, &k);
	FI(i, 1, 2 * n - 2){
		int a, b;
		scanf("%d %d", &a, &b);
		v[i] = b;
		o[i] = f[a];
		f[a] = i++;
		v[i] = a;
		o[i] = f[b];
		f[b] = i;
	}
	dfs(1, -1);
	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, s[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p){
	if(r[x]) return;

	s[x] = 1;
	fe(i, f[x], o) if(v[i] != p){
		dfs(v[i], x);
		s[x] += s[v[i]];
	}

	l[t++] = x;
}

void bfs(int x, int p, int q){
	if(q > k || r[x]) return;

	A += c[k - q];
	fe(i, f[x], o) if(v[i] != p)
		bfs(v[i], x, q + 1);

	c[q]++;
	l[t++] = q;
}

void root(int x){
	if(r[x]) return;

	a = 1 << 29;
	t = 0;
	dfs(x, 0);

	fi(i, 0, t){
		int y = l[i], m = s[x] - s[y];

		fe(j, f[y], o) if(!r[v[j]] && s[v[j]] < s[y])
			m = max(m, s[v[j]]);

		if(m < a) a = m, b = y;
	}

	t = 0;
	fe(i, f[b], o) bfs(v[i], b, 1);
	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) root(v[i]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1);

	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, y, s[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p, int m){
	s[x] = 1;
	int z = 0;

	fe(i, f[x], o) if(v[i] != p && !r[v[i]]){
		dfs(v[i], x, m);
		z = max(z, s[v[i]]);
		s[x] += s[v[i]];
	}

	z = max(z, m - s[x]);
	if(z < a) a = z, b = x, y = p;
}

void bfs(int x, int p, int q){
	if(q > k) return;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]])
		bfs(v[i], x, q + 1);
	l[t++] = q;
}

void root(int x, int m){
	a = 1 << 29;
	dfs(x, 0, m);
	s[y] = m - s[b];

	t = 0;
	fe(i, f[b], o) if(!r[v[i]]){
		int T = t;
		bfs(v[i], b, 1);

		fi(i, T, t) A += c[k - l[i]];
		fi(i, T, t) c[l[i]]++;
	}

	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) if(!r[v[i]]) root(v[i], s[v[i]]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1, n);

	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, s[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p){
	if(r[x]) return;

	s[x] = 1;
	fe(i, f[x], o) if(v[i] != p){
		dfs(v[i], x);
		s[x] += s[v[i]];
	}

	l[t++] = x;
}

void bfs(int x, int p, int q){
	if(q > k || r[x]) return;

	A += c[k - q];
	fe(i, f[x], o) if(v[i] != p)
		bfs(v[i], x, q + 1);

	c[q]++;
	l[t++] = q;
}

void root(int x){
	if(r[x]) return;

	a = 1 << 29;
	t = 0;
	dfs(x, 0);

	fi(i, 0, t){
		int y = l[i], m = s[x] - s[y];

		fe(j, f[y], o) if(s[v[j]] < s[y])
			m = max(m, s[v[j]]);

		if(m < a) a = m, b = y;
	}

	t = 0;
	fe(i, f[b], o) bfs(v[i], b, 1);
	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) root(v[i]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1);

	printf("%I64d\n", A);
}


#include <cstdio>
#include <algorithm>
#define N 50002
#define LL long long
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, k, f[N], o[N + N], v[N + N], t, a, b, s[N], d[N], c[505], l[N];
LL A;
bool r[N];

void bd(int a, int b){
	v[++t] = b; o[t] = f[a]; f[a] = t;
}

void dfs(int x, int p){
	s[x] = 1;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]]){
		dfs(v[i], x);
		s[x] += s[v[i]];
	}

	l[t++] = x;
}

void bfs(int x, int p, int q){
	if(q > k) return;
	fe(i, f[x], o) if(v[i] != p && !r[v[i]])
		bfs(v[i], x, q + 1);
	l[t++] = q;
}

void root(int x){
	a = 1 << 29;
	t = 0;
	dfs(x, 0);

	fi(i, 0, t){
		int y = l[i], m = s[x] - s[y];

		fe(j, f[y], o) if(!r[v[j]] && s[v[j]] < s[y])
			m = max(m, s[v[j]]);

		if(m < a) a = m, b = y;
	}

	t = 0;
	fe(i, f[b], o) if(!r[v[i]]){
		int T = t;
		bfs(v[i], b, 1);

		fi(i, T, t) A += c[k - l[i]];
		fi(i, T, t) c[l[i]]++;
	}
	fi(i, 0, t) c[l[i]] = 0;

	r[b] = 1;
	fe(i, f[b], o) if(!r[v[i]]) root(v[i]);
}

int main(){
	scanf("%d %d", &n, &k);

	fi(i, 1, n){
		int a, b;
		scanf("%d %d", &a, &b);
		bd(a, b);
		bd(b, a);
	}

	c[0] = 1;
	root(1);

	printf("%I64d\n", A);
	scanf("\n");
}


#include <bits/stdc++.h>

using namespace std;

#define N 50000
#define K 500

unsigned int d[N][K+1];
vector<unsigned int> g[N];
bool s[N];
int n, k, a, b, root;

long long int  contaPares (int v) {
    long long int r = 0, comb = 0;
    if (s[v]) return 0;
    d[v][0] = 1;
    s[v] = 1;

    for (vector<unsigned int>::iterator it = g[v].begin(); it != g[v].end(); it++) {
        r += contaPares(*it);
        for (int i = 0; !s[*it] && i < k && d[*it][i]; i++) d[v][i+1] += d[*it][i];
    }

    for (vector<unsigned int>::iterator it = g[v].begin(); it != g[v].end(); it++) {
        if (s[*it]) continue;

 /*
        printf("%d : ", v+1);
        for (int i = 0; i <= k; i++) printf("%d ", d[*it][i]);
        printf("\n");
*/

        for (int i = 0; i <= k-2; i++) {
  //          printf("%d : %d[%d]*(%d[%d]-%d[%d]) = %d\n", v+1, *it+1, i, v+1, k-1-i, *it+1, k-2-i, d[*it][i]*(d[v][k-1-i] - d[*it][k-2-i]));
            comb += d[*it][i]*(d[v][k-1-i] - d[*it][k-2-i]);
        }
    }

    r += d[v][k];
    r += comb/2;
    s[v] = 0;

    return r;
}

int main () {
    scanf("%d %d", &n, &k);

    for (int i = 0; i < n; i++) {
        s[i] = 0;
        for (int j = 0; j <= k; j++) d[i][j] = 0;

        if (i) {
            scanf("%d %d", &a, &b);
            a--;
            b--;

            g[a].push_back(b);
            g[b].push_back(a);
            if (i == 1) a = root;
        }
    }

    printf("%I64d\n", contaPares(root));
}