n, m = map(int, input().split())
res = [0] * n
flag = [False] * n
for i in range(m):
    s, c = map(int, input().split())
    if n > 1 and s == 1 and c == 0:
        print(-1)
        exit()
    elif flag[s - 1] == False:
        flag[s - 1] = True
        res[s - 1] = c
    elif res[s - 1] != c:
        print(-1)
        exit()

if res[0] == 0:
    print(-1)
else:
    ans = str(int(''.join(map(str, res))))
    print(ans)
