n, m = map(int, input().split())
dic = {}
ok = True
for i in range(m):
    a, b = map(int, input().split())
    if a in dic:
        if b != dic[a]:
            ok = False
    else:
        dic[a] = b

if 1 in dic:
    if n != 1 and dic[1] == 0:
        ok = False

if ok:
    l = ['0'] * n
    for i in dic.keys():
        l[i-1] = str(dic[i])
    print(''.join(l))
else:
    print(-1)