import sys
 
nmlist = list(map(int, input().split()))
N = nmlist[0]
M = nmlist[1]
order_list = [list(map(int, input().split())) for _ in range(M)]
 
Number = [0,0,0]
cnt = 0
 
for k in range(M):
    if order_list[k] == [1,0]:
        cnt += 1
 
if cnt == M:
    print(0)
    sys.exit()
for j in range(M):
    if order_list[j][0] > N:
        print(-1)
        sys.exit()
    if order_list[j][0] == 1 and order_list[j][1] == 0:
        print(-1)
        sys.exit()
 
for i in range(M):
    if Number[order_list[i][0]-N+2] != 0 and Number[order_list[i][0]-N+2] != order_list[i][1]:
        print(-1)
        sys.exit()
    Number[order_list[i][0]-N+2] = order_list[i][1]
 
if N == 1 and Number[0]+Number[1]+Number[2] == 0:
    print(0)
    sys.exit()
 
if Number[3-N] == 0:
    Number[3-N] = 1
 
print(100*Number[0]+10*Number[1]+Number[2])