import io
import sys

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

d = {}

for i in range(1, n + 1):
    d[i] = None

for itm in sc:
    if (d[itm[0]] == None) | (d[itm[0]] == itm[1]):
        d[itm[0]] = itm[1]
    else:
        print(-1)
        sys.exit()

l = list(d.values())
if l == [0]:
    print(0)
elif l[0] == 0:
    print(-1)
else:
    l = [0 if x == None else x for x in l]
    l[0] = 1 if l[0] == 0 else l[0]
    l = map(str, l)
    print("".join(l))
