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

if suuji[0] != '0':
    ans = int(''.join(suuji))
else:
    ans = -1

print(ans)
