#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)

for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

c_t = 0
for i in c_len:
    c_t += int(i)

for i in range(dig, dig*10):
    flag = False
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()
if dig == 1 and c_t == 0:
    print("0")
    exit()

print("-1")