n, m = map(int,input().split())
dic = {}
for _ in range(m):
    s,c = map(int,input().split())
    if s not in dic.keys():
        dic[s-1] = c
    elif s in dic.keys() and dic[s-1] !=c:
        res = -1
        break
for i in range(n):
    if i not in dic.keys():
        dic[i] = 0

if dic[0] ==0:
    res = -1
if res == -1:
    print('-1')
    exit()
ls = []
for i in range(n):
    ls.append(str(dic[i]))
ans = ''.join(ls)
print(ans)
