N, M = map(int,input().split())

num_dict = {1: 0, 2: 0, 3: 0}

for _ in range(M):
    temp1, temp2 = map(int,input().split())
    num_dict[temp1] = temp2
if num_dict[1] == 0:  
    print(-1)
else:
  	print(int("".join([str(num_dict[i+1]) for i in range(N)])))