import sys

n,m = map(int,input().split())
suuji = ['-1'  for i in range(n)]
# print(suuji)
for i in range(m):
    a,b = map(int,input().split())
    if suuji[a-1]=='-1' or suuji[a-1]==str(b):
        suuji[a-1]=str(b)
    else:
        print(-1)
        sys.exit()
        
for i in range(n):
    if suuji[i]=='-1':
        suuji[i]='0'

if suuji[0] == '0' and len(suuji) >= 2:
    ans = -1
else:
    ans = int(''.join(suuji))


print(ans)