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 = ''
tmp = []
ans = -1
sc2 = []
if M == 0:
    print(-1)
    exit()
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
        sc2.append([sc[i][0], sc[i][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(len(sc2)):
        if len(str(i)) < N:
            break
        if str(i)[sc2[j][0] - 1] == str(sc2[j][1]):
            cnt += 1

    if cnt >= len(sc2):
        ans = i
        break

print(ans)