import sys
input = sys.stdin.readline

N, M = list(map(int, input().split()))
ans = [-1] * N

for i in range(M):
    s, c = list(map(int, input().split()))
    s -= 1

    if not ans[s] in [c, -1]:
        print(-1)
        sys.exit()

    ans[s] = c

for i in range(N):
    if ans[i] == -1: ans[i] = 0
ans = int(''.join(map(str, ans)))

if ans == 0: ans = -1
print(ans)