N, M = map(int, input().split())
sc = [None]*M
for i in range(M):
    sc[i] = tuple(map(int, input().split()))

num = [None]*N
for i in range(M):
    if num[sc[i][0]-1] != None:
        if num[sc[i][0]-1] != sc[i][1]:
            print(-1)
            quit()
    num[sc[i][0]-1] = sc[i][1]

if num[0]==None:
    num[0] = 1

for i in range(1, N):
    if num[i] == None:
        num[i] = 0


num = map(str,num)
ans = "".join(num)
if int(ans) == 0 and N != 1:
    print(-1)
    quit()
print(ans)