import sys

n, m = map(int, input().split())
sc = {}
for _ in range(m):
    s, c = map(int, input().split())
    if s in sc:
        if sc[s] != c:
            print(-1)
            sys.exit()
    else:
        sc[s] = c

ans = [0] * n
ans[0] = 1

for s, c in sc.items():
    ans[s-1] = c

# ansチェック
if n != 1 and ans[0] == 0:
    print(-1)
else:
    print(int("".join(map(str, ans))))