N, M = map(int, input().split())
d = {}
for i in range(N):
    d[i+1] = "0"
d[1] = "1"
m = {}
ans = ""
for _ in range(M):
    zs, zc = map(int, input().split())
    if zs == 1 and zc == 0:
        ans = "-1"
        break
    if m.get(zs) and m.get(zs) == zc:
        continue
    elif m.get(zs) and m.get(zs) != zc:
        ans = "-1"
        break
    elif m.get(zs) is None:
        m[zs] = zc
if ans == "-1":
    print(-1)
else:
    for i in range(N):
        i += 1
        if m.get(i) is None:
            ans += d.get(i)
        elif m.get(i):
            ans += str(m.get(i))
    print(int(ans))
