N, M = list(map(int, input().split()))
q = []
for i in range(M):
    tmps, tmpm = list(map(int, input().split()))
    q.append((tmps, tmpm))

flag = 0

ans = [-1] * N
cnt = [0] * N

for t in q:
    s, c = t[0]-1, t[1]
    if cnt[s] == 0:
        ans[s] = c
        cnt[s] += 1
    elif ans[s] != c:
        flag = 1

for i in range(len(ans)):
    if ans[0] == 0:
        flag = 1
    elif ans[0] == -1:
        ans[0] = 1
    elif ans[i] == -1:
        ans[i] = 0


if flag == 1:
    print(-1)
else:
    print("".join(map(str, ans)))
