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

s = []
c = []
for i in range(M):
    x,y = map(int,input().split())
    s.append(x)
    c.append(y)

ans_list = [-1,-1,-1]

for i in range(M):
    if ans_list[s[i]-1] != -1 and ans_list[s[i]-1] != c[i]:
        print(-1)
        exit()
    else:
         ans_list[s[i]-1] = c[i]
#print(ans_list)
if ans_list[0] == 0 and ans_list[1] != -1:
    print(-1)
    exit()
if ans_list[0] == 0 and ans_list[2] != -1:
    print(-1)
    exit()
if ans_list[0] == 0 and ans_list[1] == -1 and ans_list[2] == -1:
    print(-1)
    exit()


for i in range(3):
    if ans_list[i] == -1:
        ans_list[i] = 0

ans = 100*ans_list[0] + 10*ans_list[1] + 1*ans_list[2]
print(ans)
