import numpy as np
N, M = map(int, input().split())
A = np.zeros([N, 2], dtype = np.int)
A[0, 0] = 1
for i in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print('-1')
        exit()
    if A[s - 1, 1] == 0:
        A[s - 1, 0] = c
        A[s - 1, 1] = 1
    elif A[s - 1, 1] == 1 and A[s - 1, 0] == c:
        continue
    else:
        print('-1')
        exit()
else:
    print(*A[:, 0], sep='')