N, M = map(int, input().split())
lists = [list(map(int, input().split())) for i in range(M)]
# print(lists)
if M > 5 or 3 < N:
    print("-1")
    exit()

number = [0]*5
# print(number)
ss = {i:int(-1) for i in range(10)}
count = 0
for i in lists:
    if ss[i[0]] == -1:
        ss[i[0]] = i[1]
    elif ss[i[0]] != i[1]:
        count += 1
        print("-1")
        break
    else:
        ss[i[0]] = i[1]
# print(ss)
if N > 1:
    if ss[1] == -1:
        ss[1] = 1
        number[N-1] = 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:
        print(ans)
    else:
        print("-1")

