N, M = [int(v) for v in input().strip().split(' ')]

def main(N, M):
    Vs = [-1 for _ in range(N)]
    for _ in range(M):
        s, c = [int(v) for v in input().strip().split(' ')]
        s -= 1
        if Vs[s] != -1 and Vs[s] != c:
            return -1
        elif Vs[s] == -1:
            Vs[s] = c
    if Vs[0] == 0:
        if len(Vs) == 0:
            return 0
        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,M))