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 s == 1:
    rb, re = 0, 10
elif s == 2:
    rb, re = 10, 100
else:
    rb, re = 100, 1000

if M == 0:
    print(rb)
    exit(0)

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

ans = 10000
for v in range(re - 1, rb - 1, -1):
    sv = str(v)
    lf = []
    for i in range(M):
        if sv[s[i] - 1] == str(c[i]):
            lf.append(True)
    if len(lf) == len(s):
        ans = min(v, ans)

if ans == 10000:
    print("-1")
else:
    print(ans)


# 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)