import java.util.*;

public class Main{

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

    int n = Integer.parseInt(sc.next());

    int m = Integer.parseInt(sc.next());

    int[] a = new int[n];

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

    for(int i=0; i<m; i++){
      s[i] = Integer.parseInt(sc.next());
      c[i] = Integer.parseInt(sc.next());
    }

    for(int i=0; i<m; i++){
      if(a[s[i]-1] != 0 && a[s[i]-1] != c[i]){
        System.out.println("-1");
        break;
      }else{
        a[s[i]-1] = c[i];
      }
      if(s[i] == 1 && c[i] == 0){
        System.out.println("-1");
        break;
      }

      if(i == m-1){
        for (int j=0; j<n; j++){

          System.out.print(a[j]);
        }

      }
    }


  }
}
