N, M = [int(v) for v in input().strip().split(' ')]
P = []
for _ in range(M):
    P.append([int(v) for v in input().strip().split(' ')])

def main(N, P):
    Vs = [-1 for _ in range(N)]
    for s, c in P:
        s -= 1
        if Vs[s] == -1:
            Vs[s] = c
        elif Vs[s] != c:
            return -1
    Vs2 = str(int(''.join([str(v if v != -1 else 0) for v in Vs])))
    return Vs2 if len(Vs2) == N else -1

print(main(N, P))