n, m = map(int, input().split())
if (n == 1 and m == 0):
    print(0)
    exit()
if (m == 0):
    print('1' + '0' * (n - 1))
    exit()
dic = {}
for i in range(m):
    s, c = map(int, input().split())
    try:
        _ = dic[s]
    except KeyError:
        if (s == 1 and c == 0 and n >= 2):
            print(-1)
            exit()
        dic[s] = c
    else:
        if (dic[s] != c):
            print(-1)
            exit()

ok = False
if (n == 0):
    start = 0
else:
    start = 10 ** (n - 1)
for i in range(10 ** (n - 1), 10 ** n):
    for k, v in dic.items():
        if (str(i)[k - 1] == str(v)):
            ok = True
        else:
            ok = False
            break
    else:
        if (ok):
            print(i)
            exit()
