n, m = map(int, input().split())
d = {}
ok = True
for i in range(m):
    s, c = map(int, input().split())
    if s not in d:
        d[s] = c
    elif d[s] != c:
        ok = False
res = ''
if not ok:
    print(-1)
else:
    for i in range(1, n+1):
        if i not in d.keys():
            res += '0'
        else:
            res += str(d[i])
    if len(res) == len(str(int(res))):
        print(res)
    else:
        print(-1)