# -*- coding: utf-8 -*-

N, M = map(int, input().split())

S = []
C = []

for i in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)


X = [None for i in range(N)]

for j in range(M):
    value = C[j]
    i = S[j] - 1

    if X[i] is None:
        X[i] = value
    elif X[i] != value:
        print(-1)
        exit(0)

if X[0] == 0 and N >= 2:
    print(-1)
else:
    print(''.join(['{}'.format(x or 0) for x in X]))