from collections import defaultdict
n,m = map(int,input().split())
ans = []
flag = True
b = defaultdict(list)
for i in range(n):
    ans.append('0')
for i in range(m):
    s,c = map(int,input().split())
    c = str(c)
    b[s].append(c)

for key,value in b.items():
    if len(set(value)) == 1:
        ans[key-1] = value[0]
    else:
        flag = False
tmp = ''
for idx,i in enumerate(ans):
    if n != 1:
        if idx == 0 and i == '0':
            i = '1'
    tmp += i
print(tmp if len(tmp) == n and flag else -1)