def read():
    N, M = list(map(int, input().strip().split()))
    S = list()
    C = list()
    for i in range(M):
        s, c = list(map(int, input().strip().split()))
        S.append(s)
        C.append(c)
    return N, M, S, C

def solve(N, M, S, C):
    digit = [-1 for i in range(4)]
    for s, c in zip(S, C):
        if digit[s] == -1 or digit[s] == c:
            digit[s] = c
        else:
            return -1
    if digit[1] == -1:
        digit[1] = 1
    for i in range(len(digit)):
        if digit[i] == -1:
            digit[i] = 0
    inumber = int(''.join(map(str, digit[1:])))
    if len(str(inumber)) == N:
        return inumber
    if inumber == 0 and N == 1:
        return inumber
    return -1


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))
