n, m = map(int, input().split())
s = [0]*m
c = [0]*m
num = ['']*n
for i in range(m):
    s[i], c[i] = map(int, input().split())
    if s[i]==1 and c[i]==0:
        print(-1)
        exit()
    elif num[s[i]-1] == '':
        num[s[i]-1] = c[i]
    elif num[s[i]-1] != c[i]:
        print(-1)
        exit()
for i in range(m):
    if num[i]=='':
        num[i] = 1
print(''.join(map(str,num)))