N, M = map(int, input().split())

dic = {}
ans = [0 for _ in range(N)]
for _ in range(M):
    s, c = map(int, input().split())
    if (dic.get(s) is not None) and (dic.get(s) != c):
        print("-1")
        break
    else:
        dic.setdefault(s, c)
        ans[s-1] = c
else:
    if ans[0] == 0:
        print("-1")
    else:
        print(''.join(str(i) for i in ans))