N,M = map(int, input().split())
temp = [0] * N
for i in range(M):
    s,c = map(int, input().split())
    s = s-1
    if temp[s] == 0 or temp[s] == c:
        temp[s] = c
    else:
        print(-1)
        exit()
ans = 0
n = N-1
for i in temp:
    ans += i*10**n
    n-=1
if N>1 and temp[0] == 0:
    print(-1)
else:
	print(ans)