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

ans = [-1] * N

for _ in range(M):
    s, i = map(int, input().split())
    s -= 1
    if ans[s] != -1 and ans[s] != i:
        print(-1)
        exit()
    ans[s] = i

ret = 0
for i in range(N):
    ret *= 10
    if ans[i] != -1:
        ret += ans[i]

ans = str(ret)

if len(ans) != N or ans == '0':
    print(-1)
else:
    print(ans)