# coding: utf-8

N, M = list(map(int, input().split()))
begin = 0 if N == 1 else 10**(N-1)

sc = [[i for i in map(int, input().split())] for j in range(M)]

flag = False
for i in range(begin, 10**N):
    for j in range(M):
        if str(i)[sc[j][0]-1] == str(sc[j][1]):
            flag = True
        else:
            flag = False
            break

    if flag == True:
        print(i)
        break

if flag == False: print(-1)