N, M = map(int,input().split())
s = [0]*M
c = [0]*M

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

ans = [0]*N
if N != 1:
    ans[0] = 1
error = 0

assign = [0]*M
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0 and N != 1:
    error += 1 

if error == 0:
    for i in range(N):
        print(ans[i], end = "")
    print()
else:
    print(-1)
