n, m = map(int, input().split())
arr = {tuple(map(int, input().split())) for _ in range(m)}

if len({x[0] for x in arr}) == len(arr):
    s_res = ['0'] * n
    for s, c in arr:
        s_res[s-1] = str(c)
    res = int(''.join(s_res))
    if n > 0 and len(str(res)) != len(s_res):
        res = -1
else:
    res = -1

print(res)