N, M = map(int, input().split())
A = [{i for i in range(0, 10)} for _ in range(N)]
A[0].discard(0)
T = True
for _ in range(M):
    s, c = map(int, input().split())
    A[s-1] = A[s-1] & set([c])
    if len(A[s-1]) == 0:
        T = False
if T:
    X = ''
    for i in range(N):
        X += str(min(A[i]))
    print(X)
else:
    print(-1)