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

public class Main {
  private static boolean solve(int n, int m, int[] as) {
    Arrays.sort(as);
    int sum = 0;
    for (int a : as) {
      sum += a;
    }

    return as[n - m] >= sum / (4 * m);
  }

  private static void execute(ContestReader reader, ContestWriter out) {
    int n = reader.nextInt();
    int m = reader.nextInt();
    int[] as = reader.nextInt(n);
    out.println(solve(n, m, as) ? "Yes" : "No");
  }

  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    ContestWriter out = new ContestWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestWriter extends PrintWriter {
  ContestWriter(PrintStream printeStream) {
    super(printeStream);
  }

  public void printList(List<? extends Object> list) {
    for (Object object : list) {
      println(object);
    }
  }

  public void printListOneLine(List<? extends Object> list) {
    List<String> stringList = new ArrayList<>();
    for (Object object : list) {
      stringList.add(object.toString());
    }
    println(String.join(" ", stringList));
  }
}

class ContestReader {
  private static final int BUFFER_SIZE = 1024;

  private final InputStream stream;
  private final byte[] buffer;
  private int pointer;
  private int bufferLength;

  ContestReader(InputStream stream) {
    this.stream = stream;
    this.buffer = new byte[BUFFER_SIZE];
    this.pointer = 0;
    this.bufferLength = 0;
  }

  private boolean hasNextByte() {
    if (pointer < bufferLength) {
      return true;
    }

    pointer = 0;
    try {
      bufferLength = stream.read(buffer);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return bufferLength > 0;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[pointer++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
      pointer++;
    }
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    while(true) {
      int b = readByte();
      if (!isPrintableChar(b)) {
        break;
      }
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }

  public String nextLine() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    while(true) {
      int b = readByte();
      if (!isPrintableChar(b) && b != 0x20) {
        break;
      }
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }

  public char nextChar() {
    return next().charAt(0);
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }

    int n = 0;
    boolean minus = false;

    {
      int b = readByte();
      if (b == '-') {
        minus = true;
      } else if ('0' <= b && b <= '9') {
        n = b - '0';
      } else {
        throw new NumberFormatException();
      }
    }

    while(true){
      int b = readByte();
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }

    long n = 0;
    boolean minus = false;

    {
      int b = readByte();
      if (b == '-') {
        minus = true;
      } else if ('0' <= b && b <= '9') {
        n = b - '0';
      } else {
        throw new NumberFormatException();
      }
    }

    while(true){
      int b = readByte();
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
    }
  }

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

  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }

  public String[] nextLine(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLine();
    }
    return array;
  }

  public char[] nextChar(int n) {
    char[] array = new char[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextChar();
    }
    return array;
  }

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

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

  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }

  public char[] nextCharArray() {
    return next().toCharArray();
  }

  public String[][] next(int n, int m) {
    String[][] matrix = new String[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = next();
      }
    }
    return matrix;
  }

  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }

  public char[][] nextChar(int n, int m) {
    char[][] matrix = new char[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextChar();
      }
    }
    return matrix;
  }

  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }

  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }

  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = false;
	//static field here

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int[] NM = readLineInt();
		int N = NM[0];
		int M = NM[1];
		int[] a = readLineInt();
		int ALL = 0;
		for(int i=0;i<N;i++) {
			ALL+=a[i];
		}

		int ans = 0;
		for(int i=0;i<N;i++) {
			if(a[i]*4*M>=ALL) {ans++;}
		}

		print(ans>=M?"Yes":"No");
	}

	//functions here
	//note that all methods should be STATIC

	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

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

    static class RedGreenApples {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int x = in.nextInt();
            int y = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            List<Long> p = new ArrayList<>();
            List<Long> q = new ArrayList<>();
            List<Long> r = new ArrayList<>();
            for (int i = 0; i < a; i++) {
                p.add(Long.parseLong(in.next()));
            }
            for (int i = 0; i < b; i++) {
                q.add(Long.parseLong(in.next()));
            }
            for (int i = 0; i < c; i++) {
                r.add(Long.parseLong(in.next()));
            }
            p.sort(Comparator.reverseOrder());
            q.sort(Comparator.reverseOrder());

            PriorityQueue<Long> s = new PriorityQueue<>(a, (o1, o2) -> Long.compare(o2, o1));
            for (int i = 0; i < x; i++) {
                s.add(p.get(i));
            }
            for (int i = 0; i < y; i++) {
                s.add(q.get(i));
            }
            for (int i = 0; i < c; i++) {
                s.add(r.get(i));
            }
            long result = 0;
            for (int i = 1; i <= x + y; i++) {
                result += s.poll();
            }

            out.println(result);

        }

    }
}

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


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

public class Main {

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

		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());

		int red[] = new int [a];
		int green[] = new int [b];
		int non[] = new int [c];

		for(int i = 0 ; i < a ;i++) {
			red[i] = Integer.parseInt(sc.next());
		}
		for(int i = 0 ; i < b ; i++) {
			green[i] = Integer.parseInt(sc.next());
		}
		for(int i = 0 ; i < c ; i++) {
			non[i] = Integer.parseInt(sc.next());
		}

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();

		Arrays.sort(red);
		Arrays.sort(green);

		for(int i = a-1 ; i >= Math.max(0, a-x) ; i--) {
			pq.add(red[i]);
		}

		for(int i = b-1 ; i >= Math.max(0, b-y) ; i--) {
			pq.add(green[i]);
		}

		for(int i = 0 ; i < c ;i++) {
			pq.add(non[i]);
		}

		while(pq.size() > x + y) {
			pq.poll();
		}

		long sum = 0;

		for(int i = 0 ; i < x+ y ; i++) {
			sum += (long)pq.poll();
		}

		System.out.println(sum);

	}

}


import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int X = scan.nextInt();
        int Y = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        ArrayList<Integer> aValueList = new ArrayList();
        ArrayList<Integer> bValueList = new ArrayList();
        ArrayList<Integer> cValueList = new ArrayList();
        for(int i = 0 ; i < A; i++) {
            aValueList.add(scan.nextInt());
        }
        for(int i = 0 ; i < B; i++) {
            bValueList.add(scan.nextInt());
        }
        for(int i = 0 ; i < C; i++) {
            cValueList.add(scan.nextInt());
        }

        Collections.sort(aValueList, Collections.reverseOrder());
        Collections.sort(bValueList, Collections.reverseOrder());
        Collections.sort(cValueList, Collections.reverseOrder());

        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
        for(int i = 0 ; i < X; i++) {
            pq.offer(aValueList.get(i));
        }
        for(int i = 0 ; i < Y; i++) {
            pq.offer(bValueList.get(i));
        }
        pq.addAll(cValueList);

        long ans = 0;
        for(int i = 0; i < X+Y; i++) {
            ans += pq.poll();
        }

        os.println(ans);

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class E {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int X = in.nextInt();
            int Y = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            long[] p = in.nextLongArray(A);
            long[] q = in.nextLongArray(B);
            long[] r = in.nextLongArray(C);
            Arrays.sort(p);
            Arrays.sort(q);
            Arrays.sort(r);
            long[] ps = Arrays.copyOfRange(p, A - X, A);
            long[] qs = Arrays.copyOfRange(q, B - Y, B);
            long[] ls = new long[X + Y];
            System.arraycopy(ps, 0, ls, 0, X);
            System.arraycopy(qs, 0, ls, X, Y);
            Arrays.sort(ls);
            long sum = LongStream.of(ls).sum();
            for (int i = 0; i < X + Y && i < C; i++) {
                long v = ls[i];
                if (v < r[C - 1 - i]) {
                    sum += r[C - 1 - i] - v;
                }
            }
            out.println(sum);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

    }
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		int x = inputs.nextInt();
		int y = inputs.nextInt();
		int red = inputs.nextInt();
		int[] r = new int[red];
		int green = inputs.nextInt();
		int[] g = new int[green];
		int clear = inputs.nextInt();
		int[] c = new int[clear];
		for(int i=0;i<red;i++) {
			r[i] = inputs.nextInt();
		}
		Arrays.sort(r);
		for(int i=0;i<green;i++) {
			g[i] = inputs.nextInt();
		}
		Arrays.sort(g);
		for(int i=0;i<clear;i++) {
			c[i] = inputs.nextInt();
		}
		Arrays.sort(c);
		PriorityQueue<Integer> app = new PriorityQueue<Integer>();
		int sum =0;
		for(int i=red-x;i<red;i++) {
			sum+=r[i];
			app.add(r[i]);
		}
		for(int i=green-y;i<green;i++) {
			sum+=g[i];
			app.add(g[i]);
		}
		int track = 0;
		while(track<clear) {
			int num = app.peek();
			if(c[track]>num) {
				sum-=num;
				app.remove();
				app.add(c[track]);
				sum+=c[track];
			}
			track++;
		}
		System.out.println(sum);
	}

}


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

public class Main {
    static void solve(MyScanner in, MyWriter out) {
        int x = in.nextInt();
        int y = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        long[] p = in.nextLongArray(a);
        long[] q = in.nextLongArray(b);
        long[] r = in.nextLongArray(c);

        Arrays.sort(p);
        Arrays.sort(q);
        reverse(p);
        reverse(q);
        long[] s = new long[x + y];
        long answer = 0;
        for (int i = 0; i < x; i++) {
            s[i] = p[i];
            answer += p[i];
        }
        for (int i = x, j = 0; j < y; i++, j++) {
            s[i] = q[j];
            answer += q[j];
        }
        Arrays.sort(s);
        Arrays.sort(r);
        for (int i = c - 1, j = 0; i >= 0; i--, j++) {
            if (r[i] <= s[j]) {
                break;
            }
            answer -= s[j];
            answer += r[i];
        }
        out.println(answer);
    }
    private static void reverse(long[] a) {
        reverse(a, 0, a.length);
    }
    private static void reverse(long[] a, int fromIndex, int toIndex) {
        if (fromIndex < 0 || toIndex > a.length || fromIndex > toIndex) {
            throw new IndexOutOfBoundsException();
        }
        for (int i = fromIndex, j = toIndex - 1; i < j; i++, j--) {
            long tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
    }
    public static void main(String[] args) {
        MyWriter w = new MyWriter(System.out);
        solve(new MyScanner(System.in), w);
        w.flush();
    }
    static final class MyScanner {
        static final int BUFFER_SIZE = 8192;
        private final InputStream in;
        private final byte[] buffer = new byte[BUFFER_SIZE];
        private int point;
        private int readLength;

        MyScanner(InputStream in) {
            this.in = in;
        }
        private byte readByte() {
            if (point < readLength) {
                byte result = buffer[point];
                point += 1;
                return result;
            }
            try {
                readLength = in.read(buffer);
            } catch (IOException e) {
                throw new AssertionError(null, e);
            }
            if (readLength == -1) {
                return -1;
            }
            point = 1;
            return buffer[0];
        }
        private static boolean isPrintableCharExceptSpace(byte c) {
            return 33 <= c && c <= 126;
        }
        public char nextChar() {
            byte c = readByte();
            while (!(c == -1 || isPrintableCharExceptSpace(c))) {
                c = readByte();
            }
            if (c == -1) {
                throw new NoSuchElementException();
            }
            return (char)c;
        }
        public String next() {
            return next(16);
        }
        public String next(int n) {
            byte c = readByte();
            while (!(c == -1 || isPrintableCharExceptSpace(c))) {
                c = readByte();
            }
            if (c == -1) {
                throw new NoSuchElementException();
            }
            StringBuilder b = new StringBuilder(n);
            do {
                b.append((char)c);
                c = readByte();
            } while (c != -1 && isPrintableCharExceptSpace(c));
            return b.toString();
        }
        public long nextLong() {
            byte c = readByte();
            while (!(c == -1 || isPrintableCharExceptSpace(c))) {
                c = readByte();
            }
            if (c == -1) {
                throw new NoSuchElementException();
            }
            boolean minus = false;
            if (c == '-') {
                minus = true;
                c = readByte();
            }
            long result = 0L;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                result = result * 10L + (c - '0');
                c = readByte();
            } while (c != -1 && isPrintableCharExceptSpace(c));
            return minus ? -result : result;
        }
        public int nextInt() {
            long n = nextLong();
            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE) {
                throw new InputMismatchException();
            }
            return (int)n;
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public int[] nextIntArray(int n) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt();
            }
            return result;
        }
        public long[] nextLongArray(int n) {
            long[] result = new long[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextLong();
            }
            return result;
        }
        public char[] nextCharArray(int n) {
            char[] result = new char[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextChar();
            }
            return result;
        }
        public char[][] next2dCharArray(int n, int m) {
            char[][] result = new char[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    result[i][j] = nextChar();
                }
            }
            return result;
        }
        public int[][] nextVerticalIntArrays(int arrayCount, int arrayLength) {
            int[][] result = new int[arrayCount][arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                for (int j = 0; j < arrayCount; j++) {
                    result[j][i] = nextInt();
                }
            }
            return result;
        }
        public long[][] nextVerticalLongArrays(int arrayCount,
                                               int arrayLength) {
            long[][] result = new long[arrayCount][arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                for (int j = 0; j < arrayCount; j++) {
                    result[j][i] = nextLong();
                }
            }
            return result;
        }
        public char[][] nextVerticalCharArrays(int arrayCount,
                                               int arrayLength) {
            char[][] result = new char[arrayCount][arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                for (int j = 0; j < arrayCount; j++) {
                    result[j][i] = nextChar();
                }
            }
            return result;
        }
    }
    static final class MyWriter extends PrintWriter {
        MyWriter(OutputStream out) {
            super(out);
        }
        public void joinAndPrintln(int[] x) {
            joinAndPrintln(x, " ");
        }
        public void joinAndPrintln(int[] x, String delimiter) {
            StringBuilder b = new StringBuilder();
            if (x.length > 0) {
                b.append(x[0]);
                for (int i = 1; i < x.length; i++) {
                    b.append(delimiter).append(x[i]);
                }
            }
            println(b.toString());
        }
        public void joinAndPrintln(long[] x) {
            joinAndPrintln(x, " ");
        }
        public void joinAndPrintln(long[] x, String delimiter) {
            StringBuilder b = new StringBuilder();
            if (x.length > 0) {
                b.append(x[0]);
                for (int i = 1; i < x.length; i++) {
                    b.append(delimiter).append(x[i]);
                }
            }
            println(b.toString());
        }
        public void joinAndPrintln(Iterable<?> iterable) {
            joinAndPrintln(iterable, " ");
        }
        public void joinAndPrintln(Iterable<?> iterable, String delimiter) {
            StringBuilder b = new StringBuilder();
            for (Iterator<?> i = iterable.iterator(); i.hasNext();) {
                b.append(i.next());
                while (i.hasNext()) {
                    b.append(delimiter).append(i.next());
                }
            }
            println(b.toString());
        }
    }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int x = cin.nextInt();
        int y = cin.nextInt();
        int A = cin.nextInt();
        int B = cin.nextInt();
        int C = cin.nextInt();
        Integer[] a = new Integer[A];
        Integer[] b = new Integer[B];
        Integer[] c = new Integer[C+x+y];
        for(int i = 0; i < A; i++){
        	a[i] = cin.nextInt();
        }
        Arrays.sort(a, 0, A, Collections.reverseOrder());
        for(int i = 0; i < B; i++){
        	b[i] = cin.nextInt();
        }
        Arrays.sort(b,0,B,Collections.reverseOrder());

        for(int i = 0; i < C; i++){
        	c[i] = cin.nextInt();
        }
        for(int i = C; i < C+x; i++){
        	c[i] = a[i-C];
        }
        for(int i = C+x; i < C+x+y; i++){
        	c[i] = b[i-C-x];
        }
        Arrays.sort(c,0,C+x+y,Collections.reverseOrder());

        long ans = 0;
        for(int i = 0; i < x+y; i++){
        	ans += c[i];
        }

        System.out.println(ans);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.io.InputStream;

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

    static class ERedAndGreenApples {
        public void solve(int testNumber, InputReader c, OutputWriter w) {
            int x = c.readInt(), y = c.readInt(), a = c.readInt(), b = c.readInt(), cc = c.readInt();
            int aa[] = c.readIntArray(a), bb[] = c.readIntArray(b), ccc[] = c.readIntArray(cc);
            Sort.mergeSort(aa, 0, a);
            Sort.mergeSort(bb, 0, b);
            PriorityQueue<Integer> pq = new PriorityQueue<>();
            for (int i = 0; i < x; i++) {
                pq.add(aa[a - 1 - i]);
            }
            for (int i = 0; i < y; i++) {
                pq.add(bb[b - 1 - i]);
            }
            PriorityQueue<Integer> pp = new PriorityQueue<>(Collections.reverseOrder());
            for (int i = 0; i < cc; i++) {
                pp.add(ccc[i]);
            }
            if (pq.peek() < pp.peek()) {
                int lll = pp.poll();
                pq.poll();
                pq.add(lll);
            }

            long res = 0;
            for (int xx : pq) {
                res += xx;
            }
            w.printLine(res);

        }

    }

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

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

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = readInt();
            }
            return array;
        }

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

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

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class Sort {
        public static void mergeSort(int[] a, int low, int high) {
            if (high - low < 2) {
                return;
            }
            int mid = (low + high) >>> 1;
            mergeSort(a, low, mid);
            mergeSort(a, mid, high);
            int[] b = Arrays.copyOfRange(a, low, mid);
            for (int i = low, j = mid, k = 0; k < b.length; i++) {
                if (j == high || b[k] <= a[j]) {
                    a[i] = b[k++];
                } else {
                    a[i] = a[j++];
                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
     Scanner scanner = new Scanner(System.in);
     int a = scanner.nextInt();
      int b = scanner.nextInt();
       int c = scanner.nextInt();
     if(Math.sqrt(a) + Math.sqrt(b) < Math.sqrt(c)){
         System.out.println("Yes");
     } else{
         System.out.println("No");
     }
    }

}

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d=c-a-b;
        if(4*a*b<d*d && d>0) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


import java.util.*;
public class Main {

  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextLong();
      if(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b))
        System.out.println("Yes");
      else
        System.out.println("No");
  }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

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

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr_temp[] = mylist.get(0).split(" ");
        int a = Integer.valueOf(arr_temp[0]);
        int b = Integer.valueOf(arr_temp[1]);
        int c = Integer.valueOf(arr_temp[2]);

        System.out.println(a + b + 2 * Math.sqrt((double) a) + Math.sqrt((double) b) < c ? "Yes" : "No");

    }

}


import java.util.Scanner;

public class Main {
	public static void main(String[] arg){
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double c = sc.nextDouble();

		if(Math.sqrt(a) + Math.sqrt(b) < Math.sqrt(c)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


import java.util.*;

public class Main {

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

    void run() {
        //入力
    	@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
    	long a = (long) Math.sqrt(sc.nextLong());
    	long b = (long) Math.sqrt(sc.nextLong());
    	long c = (long) Math.sqrt(sc.nextLong());

    	if( a + b < c) {
    		System.out.println("Yes");
    	} else {
    		System.out.println("No");
    	}
    }
}


import java.util.*;

public class Main {
	public static void main (String[] args){
		Scanner sc =  new Scanner(System.in);
		double a = sc.nextInt();
		double b = sc.nextInt();
		double c = sc.nextInt();
		if(c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.math.BigInteger;
    import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

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

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

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

      return tokenizer.nextToken("\n");
    }

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

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

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

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

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

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    BigInteger left = BigInteger.valueOf(1L);
    left = left.multiply(BigInteger.valueOf(4L));
    left = left.multiply(BigInteger.valueOf(a));
    left = left.multiply(BigInteger.valueOf(b));
    BigInteger right = BigInteger.valueOf(1L);
    right = right.multiply(BigInteger.valueOf(c - a - b));
    right = right.multiply(BigInteger.valueOf(c - a - b));
    if (left.compareTo(right) < 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


import java.util.*;

public class Main {
	public static void main (String[] args){
		Scanner sc =  new Scanner(System.in);
		double a = sc.nextInt();
		double b = sc.nextInt();
		double c = sc.nextInt();
		a = Math.sqrt(a);
		b = Math.sqrt(b);
		c = Math.sqrt(c);
		if((a+b)/c<1) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    if(c>a+b&&4*a*b<(long)Math.pow(c-a-b,2)){
      System.out.print("Yes");
    } else {
      System.out.print("No");
    }
  }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int ytotal = scanner.nextInt();
		int xtotal = scanner.nextInt();
		int c = scanner.nextInt();

		if(Math.sqrt(xtotal) + Math.sqrt(ytotal) < Math.sqrt(c)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


import java.util.*;
public class Main  {
   public static void main(String[] args)  {
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      long aa = (long)Math.sqrt(a);
        if(aa*aa> a) {
            aa--;
        }
      long bb = (long)Math.sqrt(a);
        if(bb*bb > b) {
            bb--;
        }

      long cc = (long)Math.sqrt(a);
        if(cc*cc > c) {
            cc--;
        }

      if (aa + bb < cc) {
         System.out.println("Yes");
      } else {
         System.out.println("No");
      }
   }
}


import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		double ansA = Math.sqrt(A);
		double ansB = Math.sqrt(B);
		double ansC = Math.sqrt(C);

		double AB = ansA + ansB;

		if (AB <ansC) {
			System.out.print("Yes");

		}else {
			System.out.print("No");
		}
	}
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        double c = sc.nextInt();

        double a2 = Math.sqrt(a);
        double b2 = Math.sqrt(b);
        double c2 = Math.sqrt(c);
        double d2 = c2 - (a2 + b2);

        double x3 = a2 * b2 * 2;

        if (a + b + x3 < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		if(c-a-b >= 0){
			if(4*a*b < c*c-2*a*c-2*b*c+a*a+2*a*b+b*b){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}else{
			System.out.println("No");
		}
	}
}


import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		double a=sc.nextDouble();
		double b=sc.nextDouble();
		double c=sc.nextDouble();
		if((-a-b+c)*(-a-b+c)/4>a*b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		double x = lessThanSqrt(a)+lessThanSqrt(b);
		double y = lessThanSqrt(c);
			if(x<y)
			System.out.println("Yes");
			else
			System.out.println("No");
	}

			private static long lessThanSqrt (long a) {
				long b = longSqrt(a);
				if (b*b == a) {
					return b-1;
				} else {
					return b;
				}
			}

			private static long longSqrt (long a) {
				long b = (long)Math.sqrt(a);
				// 得られた値を2乗して元の値を超える場合は
				// 誤差で1大きくなっているため
				// 誤差修正のため1引いた値を返す
				if(b*b > a) {
					b--;
				}
				return b;
			}

	}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong();
		if(c-a-b <= 0) {
			System.out.println("No");
		}else {
			BigInteger left = BigInteger.valueOf((long)Math.pow(c-a-b, 2));
			BigInteger right = BigInteger.valueOf(4*a*b);
		if(left.compareTo(right) == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		}
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

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

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

	        return tokenizer.nextToken("\n");
	    }

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

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

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

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

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


import java.util.Scanner;
public class Main{
 public static void main(String[] args) {
  Scanner kbd = new Scanner(System.in);
   int a=kbd.nextInt();
   int b=kbd.nextInt();
   int c=kbd.nextInt();
   long a2 = (long)Math.sqrt(a);
   long b2 = (long)Math.sqrt(b);
   long c2 = (long)Math.sqrt(c);

   if(a2+b2<c2){
     System.out.println("Yes");
   }else{
     System.out.println("No");
   }
}
}


import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		double ab = Math.sqrt((double)(a * b));
		String ans = "No";
		if(a + b + ab < c){
			ans = "Yes";
		}
		System.out.println(ans);
	}
}


import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double c = sc.nextDouble();
    boolean result = Math.pow(a,2)+ Math.pow(b,2)+2*a*b < Math.pow(c,2);
    if(result){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		double sa = Math.sqrt(a);
		double sb = Math.sqrt(b);
		double sc = Math.sqrt(c);
		String result = a+b + 2*Math.sqrt(a*b)< c ? "Yes" : "No";
		System.out.println(result);
		scanner.close();
	}
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong();

        double left = Math.sqrt(a)+Math.sqrt(b);
        double right = Math.sqrt(c);
        boolean result = left < right;
        if(result){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        BigDecimal a;
        a = new BigDecimal(sc.next());
        BigDecimal b;
        b = new BigDecimal(sc.next());
        BigDecimal c;
        c = new BigDecimal(sc.next());

        final Solver solver = new Solver();
        solver.solve(a, b, c);
    }
}

class Solver {
    static final String YES = "Yes";
    static final String NO = "No";
    private static final BigDecimal SQRT_DIG = new BigDecimal(1500);
    private static final BigDecimal SQRT_PRE = new BigDecimal(10).pow(SQRT_DIG.intValue());

    /**
     * Private utility method used to compute the square root of a BigDecimal.
     *
     * @author Luciano Culacciatti
     * @url http://www.codeproject.com/Tips/257031/Implementing-SqrtRoot-in-BigDecimal
     */
    private static BigDecimal sqrtNewtonRaphson(BigDecimal c, BigDecimal xn, BigDecimal precision) {
        BigDecimal fx = xn.pow(2).add(c.negate());
        BigDecimal fpx = xn.multiply(new BigDecimal(2));
        BigDecimal xn1 = fx.divide(fpx, 2 * SQRT_DIG.intValue(), RoundingMode.HALF_DOWN);
        xn1 = xn.add(xn1.negate());
        BigDecimal currentSquare = xn1.pow(2);
        BigDecimal currentPrecision = currentSquare.subtract(c);
        currentPrecision = currentPrecision.abs();
        if (currentPrecision.compareTo(precision) <= -1) {
            return xn1;
        }
        return sqrtNewtonRaphson(c, xn1, precision);
    }

    /**
     * Uses Newton Raphson to compute the square root of a BigDecimal.
     *
     * @author Luciano Culacciatti
     * @url http://www.codeproject.com/Tips/257031/Implementing-SqrtRoot-in-BigDecimal
     */
    public static BigDecimal bigSqrt(BigDecimal c) {
        return sqrtNewtonRaphson(c, new BigDecimal(1), new BigDecimal(1).divide(SQRT_PRE));
    }

    public void solve(BigDecimal a, BigDecimal b, BigDecimal c) {

        if (bigSqrt(a).add(bigSqrt(b)).compareTo(bigSqrt(c)) < 0) {
            System.out.println(YES);
        } else {
            System.out.println(NO);
        }
    }
}


import java.util.Scanner;

public class Main {
	static String s = "";

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String ans = "No";

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(Math.sqrt(a) + Math.sqrt(b) < Math.sqrt(c))
			ans = "Yes";

		System.out.println(ans);

	}

}


import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	long a, b, c;
	boolean cond = true;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		a = Long.parseLong(tokens[0]);
		b = Long.parseLong(tokens[1]);
		c = Long.parseLong(tokens[2]);

	}

	void calc() {
		long temp = c - a - b;
		temp *= temp;
		long temp2 = 4L * a * b;
		if (temp2 < temp) {
			cond = true;
		} else {
			cond = false;
		}

	}

	void showResult() {
		System.out.println((cond ? "Yes" : "No"));
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		sc.close();

		boolean ans = Math.sqrt(a * b) < (c - a - b) / 2;

		printBool(ans);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

	public static void printBool(boolean bool) {
		print(bool ? "Yes" : "No");
	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		if (a < c + b - 2*Math.sqrt(b*c)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static long ans;
	static int[] parent;//union-find用
	static int[] rank;//union-find用

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

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] s = new int[M];
		int[] c = new int[M];

		for(int i = 0;i<M ; i++) {
			s[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		ans = -1;
		int start = 0;
		int end = 0;
		if(N==1) {
			start=0;
			end = 9;
		}else if(N==2) {
			start=10;
			end=99;
		}else {
			start=100;
			end=999;
		}

		for(int i = start;ans==-1&&i<=end ; i++) {
			for(int j = 0;j<M ; j++) {
				if(String.valueOf(i).charAt(s[j]-1)-0==c[j]) {
					if(j==M-1) {
						ans=i;
						break;
					}
				}else {
					break;
				}
			}
		}

		System.out.println(ans);
	}

	//素数判定
	public static boolean isPrime(long num) {
		if (num < 2) return false;
		else if (num == 2) return true;
		else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

		double sqrtNum = Math.sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2)
		{
			if (num % i == 0)
			{
				// 素数ではない
				return false;
			}
		}

		// 素数である
		return true;
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	//Union-Find用の配列を要素数nで初期化
	static void ufInit(int n){
		parent = new int[n];
		rank = new int[n];
	}

	//Union-Findの要素の最上位の親（グループ名）を返す
	static int ufFind(int a) {
		if(parent[a]==a) {
			return a;
		}else {
			return ufFind(parent[a]);
		}
	}

	//Union-Find木を連結する
	static void ufUnite(int a, int b) {
		a = parent[a];
		b = parent[b];

		if(a==b) {
			return;
		}
		if(rank[a] > rank[b]){
			parent[b]=a;
		}else {
			parent[a]=b;
			if(rank[a]==rank[b]) {
				rank[b]++;
			}
		}
	}

	static boolean ufSame(int a, int b) {
		return ufFind(a)==ufFind(b);
	}
}

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


import java.util.*;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N=sc.nextInt(),M=sc.nextInt(),s[]=new int[M],c[]=new int[M];
		Map<Integer,Integer> a=new HashMap<Integer,Integer>();
		int ans=0;
		for(int i=0;i<M;i++) {
			s[i]=sc.nextInt();
			c[i]=sc.nextInt();
			if(!a.containsKey(s[i]-1)) {
				a.put(s[i]-1, c[i]);
			}else {
				if(a.get(s[i]-1)!=c[i]) {
					ans=-1;
					break;
				}
			}
		}
		if(a.containsKey(0)) if(a.get(0)==0) ans=-1;
		if(ans!=-1) {
			for(int i=0;i<N;i++) {
				if(a.containsKey(i)) {
					ans+=a.get(i)*(int)Math.pow(10,N-i-1);
				}else if(i==0){
					ans+=(int)Math.pow(10, N-1);
				}
			}
		}
		System.out.println(ans);
	}
}


import java.util.Scanner;

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

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] num = new int[N + 1];

        for (int i = 0 ; i < M ; i++) {
            int si = scanner.nextInt();
            int ci = scanner.nextInt();

            if (si == 1 && ci == 0) {
                System.out.println(-1);
                return;
            }
            if (num[si] != 0 && num[si] != ci) {
                System.out.println(-1);
                return;
            }
            num[si] = ci;
        }
        if (num[1] == 0) num[1] = 1;

        int ans = 0;
        int digit = 1;
        for (int i = N ; i > 0 ; i--) {
            ans += num[i] * digit;
            digit *= 10;
        }

        System.out.println(ans);
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] a = new int[m][2];

		int i = 0;
		while(i < m) {
			a[i][0] = sc.nextInt();
			a[i][1] = sc.nextInt();
			i++;
		}
		int[] z = new int[n];
		for(i = 0; i < n; i++) {
			z[i] = 10;
		}

		boolean flag = true;

		for(i = 0; i < m; i++) {
			if(z[a[i][0]-1] == 10 || z[a[i][0]-1] == a[i][1]) {
				z[a[i][0]-1] = a[i][1];
			}else {
				flag = false;
			}
		}
		if(z[0] ==0 && n>1) {
			flag = false;
		}
		if(flag == true) {
			for(i = 0; i < n; i++)  {
				if(z[i]==10) {
					z[i]=0;
				}
				System.out.print(z[i]);
			}
		}else {
			System.out.println(-1);
		}

	}

}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[][] array = new int[3][3];
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> list_answer=new ArrayList<Integer>();
		List<Integer> list_keta = new ArrayList<Integer>();
		List<Integer> list_su = new ArrayList<Integer>();
		for(int i=0;m>i;i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();
			list_keta.add(s);
			list_su.add(c);
		}

		if(n==1) {
			for(int j=0;10>j;j++) {
				int count=0;
				String x = String.valueOf(j);
				List<String> list=new ArrayList<String>(Arrays.asList(x.split("")));
				for(int i=0;m>i;i++) {
					String y = String.valueOf(list_su.get(i));
					if(list.get(list_keta.get(i)-1).equals(y))
						count++;
				}
				if(count==m)
					list_answer.add(j);
			}
		}

		else if(n==2) {
			for(int j=10;100>j;j++) {
				int count=0;
				String x = String.valueOf(j);
				List<String> list=new ArrayList<String>(Arrays.asList(x.split("")));
				for(int i=0;m>i;i++) {
					String y = String.valueOf(list_su.get(i));
					if(list.get(list_keta.get(i)-1).equals(y))
						count++;
				}
				if(count==m)
					list_answer.add(j);
			}

		}

		else {
			for(int j=100;1000>j;j++) {
				int count=0;
				String x = String.valueOf(j);
				List<String> list=new ArrayList<String>(Arrays.asList(x.split("")));
				for(int i=0;m>i;i++) {
					String y = String.valueOf(list_su.get(i));
					if(list.get(list_keta.get(i)-1).equals(y))
						count++;
				}
				if(count==m)
					list_answer.add(j);
			}

		}

		if(list_answer.size()==0)
			System.out.println(-1);
		else
			System.out.println(Collections.min(list_answer));
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	static ArrayList<Integer> adj[];
	static PrintWriter out = new PrintWriter(System.out);
	public static long mod;

	static long notmemo[][][];
	static int k;
	static int a[];
	static int b[];
	static int m;
	static char c[];

	static int trace[];
	static int h;
	static int x;
	static int ans1;
	static int ans2;
    static char t[];
	static char l[];
	static char r[];
    public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    TreeSet<Integer> set=new TreeSet<>();
    int a[]=new int[n];
    while(m-->0) {
    	int s=sc.nextInt();
    	int c=sc.nextInt();
    	if(set.contains(s)&&c!=a[s-1]) {
    	System.out.println(-1);
    	return;
    	}
    	else
    	a[s-1]=c;
    	set.add(s);

    }
    boolean f=false;
    for (int i = 0; i < a.length&&n>1; i++) {
		if(a[i]==0&&!f) {
			System.out.println(-1);
			return;
		}
		else if(a[i]!=0&&!f) {
			f=true;
		}
	}
    for(int x:a) {
    	System.out.print(x);
    }
    }
	public static int solve(char m[]) {
		int count[]=new int[c.length+1];
		for (int i = 1; i < count.length; i++) {
			count[i]=count[i-1]+((m[i-1]==c[i-1])? 1:0);
		}
		int ans=(int) 1e9;
		for (int i = 0; i <c.length-k+1; i++) {
			ans=Math.min(ans,k-count[i+k]+count[i]);

		}
		return ans;
}
	static int nomnom[];
	static long fac[];
	   public static long dp(int idx,int count,int state) {
		   if(count>3) {
			   return 0;
		   }
		   if(idx==h) {
			   return 1;
		   }
		   if(notmemo[idx][count][state]!=-1) {
			   return notmemo[idx][count][state];
		   }
		   //System.out.println("the sun will come out tommorow "+count);
		   long ans=0;
		   for (int i = 0; i <=9; i++) {
			if(state==1&&i!=0) {
				ans+=dp(idx+1, count+1, state);
			}
			else if(i==0&&(l[idx]!='0'||state==1)) {
				ans+=dp(idx+1, count, 1);
			}
			else if(i==0&&(l[idx]=='0'&&state==0)) {
				ans+=dp(idx+1, count, state);
			}
			else if(state==0&&i==(Integer.parseInt(""+l[idx]))) {
				ans+=dp(idx+1, count+1, state);
			}

			else if(state==0&&i<(Integer.parseInt(""+l[idx]))) {
				ans+=dp(idx+1, count+1,1);
		   }

       }

	return notmemo[idx][count][state]=ans;
	   }

	static class book implements Comparable<book> {
		int idx;
		long score;

		public book(int i, long s) {
			idx = i;
			score = s;
		}

		public int compareTo(book o) {
			return (int) (o.score - score);
		}
	}

	static class library implements Comparable<library> {
		int numofbooks;
		int signup;
		int shiprate;
		int idx;

		public library(int a, int b, int c, int idx) {
			numofbooks = a;
			signup = b;
			shiprate = c;
			this.idx = idx;
		}

		@Override
		public int compareTo(library o) {
		if(signup==o.signup) {
			  return o.numofbooks-numofbooks;
		}
		return signup - o.signup;

		}
	}

	static boolean isPal(String s) {
		int j = s.length() - 1;
		c = s.toCharArray();
		Arrays.sort(c);
		for (int i = 0; i < c.length; i++) {

		}
		return true;
	}

	static String s;

	static boolean isOn(int S, int j) {
		return (S & 1 << j) != 0;
	}

	static int y, d;

	static void extendedEuclid(int a, int b) {
		if (b == 0) {
			x = 1;
			y = 0;
			d = a;
			return;
		}
		extendedEuclid(b, a % b);
		int x1 = y;
		int y1 = x - a / b * y;
		x = x1;
		y = y1;
	}

	static boolean f = true;

	static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = Math.max(sTree[index << 1], sTree[index << 1 | 1]);
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return Math.max(q1, q2);

		}
	}

	static int memo[][];

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			max = new int[N];
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
				max[i] = i;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];
				max[x] = Math.max(max[x], max[y]);

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;
				max[y] = Math.max(max[x], max[y]);

			}
		}

		private int getmax(int j) {
			return max[findSet(j)];
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	/**
	 * private static void trace(int i, int time) { if(i==n) return;
	 *
	 *
	 * long ans=dp(i,time);
	 * if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
	 *
	 * trace(i+1, time+a[i].t);
	 *
	 * l1.add(a[i].idx); return; } trace(i+1,time);
	 *
	 * }
	 **/

	static class incpair implements Comparable<incpair> {
		int a;
		long b;
		int idx;

		incpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(incpair e) {
			return (int) (b - e.b);
		}
	}

	static class decpair implements Comparable<decpair> {
		int a;
		long b;
		int idx;

		decpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(decpair e) {
			return (int) (e.b - b);
		}
	}

	static long allpowers[];

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long dirg[][];
	static Edge[] driver;

	static int n;

	static class Edge implements Comparable<Edge> {
		int node;
		long cost;

		Edge(int a, long dirg) {
			node = a;
			cost = dirg;
		}

		public int compareTo(Edge e) {
			return (int) (cost - e.cost);
		}
	}

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Pair implements Comparable<Pair> {
		int a, b;

		Pair(int x, int y) {
			a = x;
			b = y;
		}

		@Override
		public int compareTo(Pair c) {
			return b-c.b;
		}

	}

	static long[][] comb;

	static class Triple implements Comparable<Triple> {

		int l;
		int r;
		long cost;
		int idx;

		public Triple(int a, int b, long l1, int l2) {
			l = a;
			r = b;
			cost = l1;
			idx = l2;
		}

		public int compareTo(Triple x) {
			if (l != x.l || idx == x.idx)
				return l - x.l;
			return -idx;
		}

	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/
	public static boolean FindAllElements(int n, int k) {
		int sum = k;
		int[] A = new int[k];
		Arrays.fill(A, 0, k, 1);

		for (int i = k - 1; i >= 0; --i) {

			while (sum + A[i] <= n) {

				sum += A[i];
				A[i] *= 2;
			}
		}
		if (sum == n) {
			return true;
		} else
			return false;
	}

	static boolean vis2[][];

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}

	static ArrayList<Pair> a1[];
	static int memo1[];

	static boolean vis[];
	static TreeSet<Integer> set = new TreeSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long ans, long b) {
		if (b == 0) {
			return ans;
		}
		return gcd(b, ans % b);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static long[] schuffle(long[] sad) {
		for (int i = 0; i < sad.length; i++) {
			int x = (int) (Math.random() * sad.length);
			long temp = sad[x];
			sad[x] = sad[i];
			sad[i] = temp;
		}
		return sad;
	}

	static int V;
	static long INF = (long) 1E16;

	static class Edge2 {
		int node;
		long cost;
		long next;

		Edge2(int a, int c, Long long1) {
			node = a;
			cost = long1;
			next = c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

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

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	static ArrayList<Integer> adj[];
	static PrintWriter out = new PrintWriter(System.out);
	public static long mod;

	static long notmemo[][][];
	static int k;
	static int a[];
	static int b[];
	static int m;
	static char c[];

	static int trace[];
	static int h;
	static int x;
	static int ans1;
	static int ans2;
    static char t[];
	static char l[];
	static char r[];
    public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    TreeSet<Integer> set=new TreeSet<>();
    int a[]=new int[n];
    while(m-->0) {
    	int s=sc.nextInt();
    	int c=sc.nextInt();
    	if(set.contains(s)&&c!=a[s-1]) {
    		System.out.println(-1);
    		return;
    	}
    	set.add(s);

    	a[s-1]=c;

    }
    if(n==3&&a[2]==0) {
    	System.out.println(-1);
		return;

    }
    if(n==2&&a[1]==0)
    {  	System.out.println(-1);
	return;
    }
    for(int x:a) {
    	System.out.print(x);
    }
    }
	public static int solve(char m[]) {
		int count[]=new int[c.length+1];
		for (int i = 1; i < count.length; i++) {
			count[i]=count[i-1]+((m[i-1]==c[i-1])? 1:0);
		}
		int ans=(int) 1e9;
		for (int i = 0; i <c.length-k+1; i++) {
			ans=Math.min(ans,k-count[i+k]+count[i]);

		}
		return ans;
}
	static int nomnom[];
	static long fac[];
	   public static long dp(int idx,int count,int state) {
		   if(count>3) {
			   return 0;
		   }
		   if(idx==h) {
			   return 1;
		   }
		   if(notmemo[idx][count][state]!=-1) {
			   return notmemo[idx][count][state];
		   }
		   //System.out.println("the sun will come out tommorow "+count);
		   long ans=0;
		   for (int i = 0; i <=9; i++) {
			if(state==1&&i!=0) {
				ans+=dp(idx+1, count+1, state);
			}
			else if(i==0&&(l[idx]!='0'||state==1)) {
				ans+=dp(idx+1, count, 1);
			}
			else if(i==0&&(l[idx]=='0'&&state==0)) {
				ans+=dp(idx+1, count, state);
			}
			else if(state==0&&i==(Integer.parseInt(""+l[idx]))) {
				ans+=dp(idx+1, count+1, state);
			}

			else if(state==0&&i<(Integer.parseInt(""+l[idx]))) {
				ans+=dp(idx+1, count+1,1);
		   }

       }

	return notmemo[idx][count][state]=ans;
	   }

	static class book implements Comparable<book> {
		int idx;
		long score;

		public book(int i, long s) {
			idx = i;
			score = s;
		}

		public int compareTo(book o) {
			return (int) (o.score - score);
		}
	}

	static class library implements Comparable<library> {
		int numofbooks;
		int signup;
		int shiprate;
		int idx;

		public library(int a, int b, int c, int idx) {
			numofbooks = a;
			signup = b;
			shiprate = c;
			this.idx = idx;
		}

		@Override
		public int compareTo(library o) {
		if(signup==o.signup) {
			  return o.numofbooks-numofbooks;
		}
		return signup - o.signup;

		}
	}

	static boolean isPal(String s) {
		int j = s.length() - 1;
		c = s.toCharArray();
		Arrays.sort(c);
		for (int i = 0; i < c.length; i++) {

		}
		return true;
	}

	static String s;

	static boolean isOn(int S, int j) {
		return (S & 1 << j) != 0;
	}

	static int y, d;

	static void extendedEuclid(int a, int b) {
		if (b == 0) {
			x = 1;
			y = 0;
			d = a;
			return;
		}
		extendedEuclid(b, a % b);
		int x1 = y;
		int y1 = x - a / b * y;
		x = x1;
		y = y1;
	}

	static boolean f = true;

	static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = Math.max(sTree[index << 1], sTree[index << 1 | 1]);
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return Math.max(q1, q2);

		}
	}

	static int memo[][];

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			max = new int[N];
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
				max[i] = i;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];
				max[x] = Math.max(max[x], max[y]);

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;
				max[y] = Math.max(max[x], max[y]);

			}
		}

		private int getmax(int j) {
			return max[findSet(j)];
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	/**
	 * private static void trace(int i, int time) { if(i==n) return;
	 *
	 *
	 * long ans=dp(i,time);
	 * if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
	 *
	 * trace(i+1, time+a[i].t);
	 *
	 * l1.add(a[i].idx); return; } trace(i+1,time);
	 *
	 * }
	 **/

	static class incpair implements Comparable<incpair> {
		int a;
		long b;
		int idx;

		incpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(incpair e) {
			return (int) (b - e.b);
		}
	}

	static class decpair implements Comparable<decpair> {
		int a;
		long b;
		int idx;

		decpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(decpair e) {
			return (int) (e.b - b);
		}
	}

	static long allpowers[];

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long dirg[][];
	static Edge[] driver;

	static int n;

	static class Edge implements Comparable<Edge> {
		int node;
		long cost;

		Edge(int a, long dirg) {
			node = a;
			cost = dirg;
		}

		public int compareTo(Edge e) {
			return (int) (cost - e.cost);
		}
	}

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Pair implements Comparable<Pair> {
		int a, b;

		Pair(int x, int y) {
			a = x;
			b = y;
		}

		@Override
		public int compareTo(Pair c) {
			return b-c.b;
		}

	}

	static long[][] comb;

	static class Triple implements Comparable<Triple> {

		int l;
		int r;
		long cost;
		int idx;

		public Triple(int a, int b, long l1, int l2) {
			l = a;
			r = b;
			cost = l1;
			idx = l2;
		}

		public int compareTo(Triple x) {
			if (l != x.l || idx == x.idx)
				return l - x.l;
			return -idx;
		}

	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/
	public static boolean FindAllElements(int n, int k) {
		int sum = k;
		int[] A = new int[k];
		Arrays.fill(A, 0, k, 1);

		for (int i = k - 1; i >= 0; --i) {

			while (sum + A[i] <= n) {

				sum += A[i];
				A[i] *= 2;
			}
		}
		if (sum == n) {
			return true;
		} else
			return false;
	}

	static boolean vis2[][];

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}

	static ArrayList<Pair> a1[];
	static int memo1[];

	static boolean vis[];
	static TreeSet<Integer> set = new TreeSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long ans, long b) {
		if (b == 0) {
			return ans;
		}
		return gcd(b, ans % b);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static long[] schuffle(long[] sad) {
		for (int i = 0; i < sad.length; i++) {
			int x = (int) (Math.random() * sad.length);
			long temp = sad[x];
			sad[x] = sad[i];
			sad[i] = temp;
		}
		return sad;
	}

	static int V;
	static long INF = (long) 1E16;

	static class Edge2 {
		int node;
		long cost;
		long next;

		Edge2(int a, int c, Long long1) {
			node = a;
			cost = long1;
			next = c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

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

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}
	}
}


import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

public class Main {

    public static void main(String[] args) {

        // 入力データの取得
        Scanner scanner = new Scanner(System.in);
        int digitNum = scanner.nextInt();
        int checkNum = scanner.nextInt();
        Map<Integer, Integer> resultMap = new HashMap<>();
        for (int count = 0; count < checkNum; count++) {
            int checkDigitNumber = scanner.nextInt();
            int displayDigitNumber = scanner.nextInt();
            if (!resultMap.isEmpty() && resultMap.get(checkDigitNumber) != null && resultMap.get(checkDigitNumber) != displayDigitNumber) {
                System.out.println("-1");
                scanner.close();
                return;
            } else {
                resultMap.put(checkDigitNumber, displayDigitNumber);
            }
        }
        scanner.close();

        // 結果の出力
        StringBuilder displayBuilder = new StringBuilder();
        if (resultMap.get(1) != null && resultMap.get(1) == 0) {
            System.out.println("-1");
            return;
        } else {
            if (digitNum == 0) {
                if (resultMap.get(1) == null) {
                    displayBuilder.append(0);
                } else {
                    displayBuilder.append(resultMap.get(1));
                }
            } else {
                for (int count = 1; count <= digitNum; count++) {
                    if (count != 1 && resultMap.get(count) == null) {
                        displayBuilder.append(0);
                    } else if (count == 1 && resultMap.get(count) == null) {
                        displayBuilder.append(1);
                    } else {
                        displayBuilder.append(resultMap.get(count));
                    }
                }
            }
            System.out.println(displayBuilder.toString());
        }

    }

}


import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int flg = 0;
    if(N == 1 && M == 0){
        System.out.println("0");
        flg = 1;
    }
    int[] n = new int[N];
    int[] flg2 = new int[N];
    for(int i = 0; i < M; i++){
      int s = sc.nextInt();
      int c = sc.nextInt();
      if(N == 1 && M == 1){
        System.out.println(c);
        flg = 1;
        break;
      } else if(s == 1 && c == 0){
        System.out.println("-1");
        flg = 1;
        break;
      } else if(n[s - 1] == 0 || n[s - 1] == c || flg2[s - 1] == 0){
        n[s - 1] = c;
        flg2[s - 1] = 1;
      } else {
        System.out.println("-1");
        flg = 1;
        break;
      }
    }
    if(N != 1 && n[0] == 0){
      n[0] = 1;
    }
    if(flg == 0){
      for(int i = 0; i < N; i++){
        System.out.print(n[i]);
      }
    }
  }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = -1;
        }
        for (int i = 0; i < m; i++) {
            int s = sc.nextInt();
            int c = sc.nextInt();
            if (n!=1 &&s == 1 && c == 0) {
                System.out.println(-1);
                return;
            } else if (num[s - 1] > -1 && num[s - 1] != c) {
                System.out.println(-1);
                return;
            } else {
                num[s - 1] = c;
            }
        }
        int ans = 0, digit = 1;
        if(n == 3 && num[0] == -1) num[0] = 1;
        if(n == 2 && num[0] == -1) num[0] = 1;
        for (int i = n - 1; i >= 0; i--) {
//            if(n-1==i && num[n-i-1] == -1) num[n-i-1] = 1;
            if (num[i] == -1) num[i] = 0;

            ans += num[i] * digit;
            digit *= 10;
        }
        System.out.println(ans < 0? -1: ans);
    }
}


import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Map<Integer,Integer> map = new TreeMap<>();
		for(int i = 0;i < M;i++){
			int s = sc.nextInt();
			int c = sc.nextInt();
			if(map.containsKey(s-1)){
				System.out.println(-1);
				return;
			}else{
				map.put(s-1, c);
			}
		}
		sc.close();
		if(N>=2){
			for(int i = 0;i < N;i++){
				if(!map.containsKey(i)){
					map.put(i, 0);
					if(i == N-1){
						System.out.println(-1);
						return;
					}
				}
			}
			for(Map.Entry<Integer, Integer> ent : map.entrySet()){
				System.out.print(ent.getValue());
			}
		}else{
			System.out.println(0);
		}
	}
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int anser = -1;

		int n = scan.nextInt();
		int m = scan.nextInt();

		int[] s = new int[m];
		int[] c = new int[m];

		for (int i = 0; i < m; i++) {
			s[i] = scan.nextInt();
			c[i] = scan.nextInt();
		}

		if(m == 0) {
			if(n == 1) {
				anser = 0;
			}
			if(n == 2) {
				anser = 10;
			}
			if(n == 3) {
				anser = 100;
			}
		}

		if (n == 1) {
			out_of_loop: for (int i = 0; i <= 9; i++) {
				for (int j = 0; j < m; j++) {
					if (i != c[j]) {
						break;
					}
					if (j == m - 1) {
						anser = i;
						break out_of_loop;
					}
				}
			}
		}

		if (n == 2) {
			out_of_loop: for (int i = 10; i <= 99; i++) {
				for (int j = 0; j < m; j++) {
					if (s[j] == 1) {
						if (i / 10 != c[j]||c[j] == 0) {
							break;
						}
					}
					if (s[j] == 2) {
						if (i % 10 != c[j]) {
							break;
						}
					}
					if (j == m - 1) {
						anser = i;
						break out_of_loop;
					}

				}
			}
		}

		if (n == 3) {
			out_of_loop: for (int i = 100; i <= 999; i++) {
				for (int j = 0; j < m; j++) {
					if (s[j] == 1) {
						if (i / 100 != c[j] || c[j] == 0) {
							break;
						}
					}
					if (s[j] == 2) {
						if (i / 10 % 10 != c[j]) {
							break;
						}
					}

					if (s[j] == 3) {
						if (i % 10 != c[j]) {
							break;
						}
					}
					if (j == m - 1) {
						anser = i;
						break out_of_loop;
					}

				}
			}
		}

		System.out.println(anser);
	}

}


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

public class Main {

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

	class P{
		int s;
		int c;
		P(int s, int c){
			this.s=s;
			this.c=c;
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();

		ArrayList<P> p = new ArrayList<P>();
		for(int i=0; i<m; i++) {
			p.add(new P(sc.nextInt(),sc.nextInt()));
		}

		for(int i=0; i<1000; i++) {
			ArrayList<Integer> d = new ArrayList<Integer>();
			d.add(i%10);
			int ni = i/10;
			int keta=1;
			while(ni>0) {
				d.add(0,ni%10);
				ni /= 10;
				keta++;
			}
			if(keta != n) continue;

			boolean ok = true;
			for(int j=0 ;j<p.size(); j++) {
				int s = p.get(j).s;
				int c = p.get(j).c;
				if(d.get(s-1) != c) {
					ok = false;
				}
			}
			if(ok) {
				System.out.println(i);
				sc.close();
				return;
			}
		}
		System.out.println(-1);
		sc.close();
	}
}


import java.util.*;

public class Main {

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

		Map<Integer,Integer> sc_map = new HashMap<Integer, Integer>();
		boolean isUnique = true;
		boolean isExist = true;

		// 重複を取る、重複に矛盾があればその場でエラーとする
		for (int i=0; i<M; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();

			// 存在チェック
			if(sc_map.containsKey(s)){
				int x = sc_map.get(s);
				if(x != c){
					// 重複に矛盾
		    		System.out.println(-1);
					return;
				}
				// putはしない
			}else{
				sc_map.put(s, c);
			}
        }

        // ０チェック
		int answer = -1;
		if(N == 1){
			if(sc_map.containsKey(1)){
				answer = sc_map.get(1);
			}else{
				answer = 0;
			}
		}else if(N == 2){
			if(sc_map.containsKey(1)){
				if(sc_map.get(1) == 0){
					isExist = false;
				}
				answer = sc_map.get(1)* 10;
			}else{
				answer = 10;
			}

			if(sc_map.containsKey(2)){
				answer += sc_map.get(2);
			}

		}else if(N == 3){
			if(sc_map.containsKey(1)){
				if(sc_map.get(1) == 0){
					isExist = false;
				}
				answer = sc_map.get(1)* 100;
			}else{
				answer = 100;
			}

			if(sc_map.containsKey(2)){
				if(sc_map.get(2) == 0){
					isExist = false;
				}
				answer += sc_map.get(2)* 10;
			}

			if(sc_map.containsKey(3)){
				answer += sc_map.get(3);
			}
		}

        if(isUnique && isExist){
    		System.out.println(answer);
        }else{
    		System.out.println(-1);
        }
	}

}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] s = new int[5];
        int[] c = new int[5];
        for(int i=0;i<M;i++){
            s[i] = Integer.parseInt(sc.next());
            c[i] = Integer.parseInt(sc.next());
        }
        int[] result = new int[3];
        for(int i=0;i<M;i++){
            if(s[i] == 1 && c[i] == 0){
                result[0] = -1;
                break;
            }else{
                if(result[s[i] - 1] != 0 && result[s[i] - 1] != c[i]){
                    result[0] = -1;
                    break;
                }else{
                    result[s[i] - 1] = c[i];
                }
            }
        }
        if(result[0] == -1){
            System.out.println(result[0]);
        }else{
            System.out.println(result[0] * 100 + result[1] * 10 + result[2]);
        }
    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] seisu = new int[n];
		Map<Integer, Integer> sici = new HashMap<>();
		for(int i = 0; i < m; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();
			if(s == 1 && c == 0) {
				System.out.println(-1);
				System.exit(0);
			}
			if(sici.containsKey(s)) {
				if(sici.get(s) != c) {
					System.out.println(-1);
					System.exit(0);
				}
			}
			sici.put(s, c);
			seisu[s - 1] = c;
		}

		if(!sici.containsKey(1)) {
			seisu[0] = 1;
		}

		for(int value : seisu) {
			System.out.print(value);
		}

		sc.close();
	}
}