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

s = []
c = []
tar = [0 for i in range(n)]
for i, j in sc:
    s.append(i)
    c.append(j)

for i in range(m):
    if tar[s[i]-1] != 0:
        if tar[s[i]-1] != c[i]:
            print(-1)
            exit()
        else:
            continue
    else:
        tar[s[i]-1] = c[i]

if 1 in s and tar[0] == 0:
    print(-1)
else:
    if tar[0]==0:
        tar[0]=1
        print(int("".join(map(str, tar))))
    else:
        print(int("".join(map(str, tar))))
