N = int(input())
M = int(input())

frag = True
for i in range(N):
    A[i] = -1
for i in range(M):
    si = int(input())
    ci = int(input())
    if A[si] != -1 and A[si] != ci:
        frag = False
        break
    else if si == 1 and ci == 0:
        frag = False
        break
    else:
        A[si] = ci

ans = 0
for i in range(N):
    if A[N-i-1] == -1:
        A[N-i-1] = 0
    ans += A[N-i-1]*(10**i)
    
if frag:
    print(ans)
else:
    print(-1)