import sys

n, m = map(int, input().split())
ltr_list = [""]*3
for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    c = str(c)
    if ltr_list[s] == "":
        ltr_list[s] = c
    elif ltr_list[s] != "" and ltr_list[s] == c:
        continue
    else:
        print(-1)
        sys.exit()

cnt = 0
for i in range(len(ltr_list)):
    if ltr_list[i] == "":
        ltr_list[i] = str(0)
        cnt += 1

if cnt == 3:
    print(-1)
    sys.exit()

ans = ''.join(ltr_list).lstrip('0')
if n > len(ans):
    print(-1)
else:
    print(ans)