n,m = map(int, input().split())
num = [0]*n
Dup = [True]*n
ans = 0

for i in range(m):
    s,c = map(int, input().split())

    if num[s-1] == c or Dup[s-1]:
        num[s-1] = c
        Dup[s-1] = False
    else:
        ans = -1

if ans != -1 and num[0] != 0:
    print(*num,sep='')
else:
    print(-1)
