N,M = map(int,input().split())
ans = [10]*N
for i in range(M):
    si,ci = map(int,input().split())
    if ans[si-1] == 10:
        ans[si-1] = ci
    elif ans[si-1] != ci:
        ans[0] = -1

for i in range(1,N):
    if ans[i] == 10:
        ans[i] = 0
if ans[0] == 10: ans[0] = 1

if ans[0] > 0:
    res = 0
    for i in range(N):
        res += ans[i]*10**(N-i-1)
elif ans[0] == -1:
    res = -1
else:
    if N == 1:
        res = 0
    else:
        res = -1

print(res)