N, M = list(map(int, input().split()))
s, c = [], []
mapSC = {}
for _ in range(M):
    si, ci = list(map(int, input().split()))
    s.append(si)
    c.append(ci)
    if si not in mapSC:
        mapSC[si] = ci
    else:
        if mapSC[si] != ci:
            print("-1")
            exit(0)

if len(mapSC) > N:
    print("-1")
    exit(0)

if N > 1 and s[0] == 0:
    print("-1")
    exit(0)

if s == 1:
    rb, re = 0, 10
elif s == 2:
    rb, re = 10, 100
else:
    rb, re = 100, 1000

ans = -1
for v in range(rb, re):
    sv = "{}".format(v)
    lf = []
    for i in range(M):
        lf.append(int(sv[s[i] - 1]) == int(c[i]))
    if all(lf):
        ans = v
        break
    # print(sv, lf, all(lf))

print(ans)