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 = ''

for i in range(M):
    if i != 0:
        if chk[sc[i][0] - 1] != 0 and chk[sc[i][0] - 1] != sc[i][1]:
            print(-1)
            exit()
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
    else:
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
for i in chk:
    ans += str(i)
if ans == '000':
    print(-1)
else:
    print(int(ans))