using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
	var input = ReadLine().Split(' ').Select(int.Parse).ToArray();
    var n = input[0];
    var m = input[1];
    var x = new int[m,2];
    
    for(var i = 0;i < m;i++){
    	var k = ReadLine().Split(' ');
      	x[i,0] = int.Parse(k[0]);
        x[i,1] = int.Parse(k[1]);
    }
    
    var z = new int[n];
    
    for(var i = 0;i < n;i++){
		z[i] = -1;
    }
    
    for(var i = 0;i < m;i++){
      	var t = x[i,0]-1;
		if(z[t] != -1){
          if(z[t] != x[i,1]){
          	Write("-1");
        	return;
          }
        }
      	z[t] = x[i,1];
    }
    
    if(z.All(a => a <= 0)){
    	Write("-1");
        return;
    }else if(z[0] == -1){
    	z[0] = 1;
    }else if(z[0] == 0){
    	Write("-1");
        return;
    }
    
    for(var i = 0;i < n;i++){
    	if(z[i] == -1){
			z[i] = 0;
    	}
    }
    
	for(var i = 0;i < n;i++){
    	Write(z[i]);
    }

  }
}