N, M = map(int, input().split())
lists = [list(map(int, input().split())) for i in range(M)]

number = [0, 0, 0, 0, 0]
ss = {i:int(10) for i in range(10)}
count = 0
for i in lists:
    if ss[i[0]] == 10:
        ss[i[0]] = i[1]
    elif ss[i[0]] != i[1]:
        count += 1
        print("1 -1")
        break
    else:
        ss[i[0]] = i[1]


# for i in lists:
#     if i[1] < ss[i[0]]:
#         ss[i[0]] = i[1]
# print(ss)

for i in lists:
    number[i[0]+1] = ss[i[0]]
# print(number)
ans = number[N-1:]
ans = "".join(map(str, ans))
ans = int(ans)
ans = str(ans)
if N == 1:
    ans = ans[0]

if count != 1:
    if len(ans) == N or N == 1:
        print(ans)
    else:
        print("2 -1")