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[] array = new int[3];
    for(int i = 0; i < 3; i++){
      array[i] = -1;
    }
    for(int i = 0; i < m; i++){
      int s = sc.nextInt()-1;
      int c = sc.nextInt();
      if(n!=1&&s==0&&c==0){
        System.out.println(-1);
        return;
      }
      if(array[s] != -1&&array[s] != c){
        System.out.println(-1);
        return;
      }
      if(array[s] == -1){
        array[s] = c;
      }
    }
    for(int i = 0; i < 3; i++){
      if(n != 1&& i == 0 && array[i] == -1){
        array[i] = 1;
      }
      if(array[i] == -1){
        array[i] = 0;
      }
    }
      int num = 0;
      for(int i = 0; i < n; i++){
        if(i != 0){
          num = num*10;
        }
        num = num + array[i];
      }
      System.out.println(num);
    }
  }