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]

for j in range(M):
    if order_list[j][0] > N:
        print(-1)
        sys.exit()
    if order_list[j][0] == N and order_list[j][1] == 0:
        print(-1)
        sys.exit()

for i in range(M):
    if Number[order_list[i][0]-1] != 0 and Number[order_list[i][0]-1] != order_list[i][1]:
        print(-1)
        sys.exit()
    Number[order_list[i][0]-1] = order_list[i][1]

if 100*Number[0]+10*Number[1]+Number[2] == 0:
    print(-1)
    sys.exit()

print(100*Number[0]+10*Number[1]+Number[2])
