N, M = map(int, input('').split(' '))
list = []
flag = []
num = 0
for j in range(N):
    if(j == N - 1):
        list.append(1)
    else:
        list.append(0)
    flag.append(0)
if(M == 0):
    M = 1
for i in range(M):
    s, c = map(int, input('').split(' '))
    s = int(s)
    if flag[N - s] == 1 and list[N - s] != c:
        print(-1)
        exit(0)
    else:
        list[N - s] = c
        flag[N - s] = 1
for j in range(N):
    num += list[j] * 10 ** j
if num > 0:
    print(num)
else:
    print(-1)