N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]

li = [0]*N
li[0] = 1
te = [[] * 1 for i in range(N)]

check = 0
for j in range(M):
    a = sc[j][0] - 1
    b = sc[j][1]
    te[a].append(b)

for i in range(M):
    if sc[i][0] == 1 and sc[i][1] == 0:
        ans = -1
        check = 1
        break

for k in range(N):
    if len(set(te[k])) >= 2:
        ans = -1
        check = 1
        break
    else:
        if len(set(te[k])) == 1:
            li[k] = te[k][0]

if check == 0:
    ans = ""
    for s in li:
        ans += str(s)
print(ans)