n,m = map(int,input().split())
ans = []
flag = True
for i in range(n):
    ans.append('0')
for i in range(m):
    s,c = map(int,input().split())
    c = str(c)
    if ans[s-1] == '0' or ans[s-1] == c:
        ans[s-1] = c
    else:
        flag = False
tmp = ''
for idx,i in enumerate(ans):
    if idx == 0 and i == '0':
        flag = False
    tmp += i
print(tmp if len(tmp) == n and flag else -1)