N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''

ans = -1
for i in range(M):
    if cnt[sc[i][0] - 1] == 0:
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
    else:
        if  chk[sc[i][0] - 1] != sc[i][1]:
            print(-1)
            exit()
for i in range(0, 1000):
    cnt = 0
    for j in range(M):
        if len(str(i)) < N:
            break
        if str(i)[sc[j][0] - 1] == str(sc[j][1]):
            cnt += 1

    if cnt >= N or cnt >= M:
        ans = i
        break

print(ans)