import math
def main():
    N, M = map(int, input().split())
    f = [0 for i in range(N)]
    N = [0 for i in range(N)]


    for _ in range(M):
        s, c = map(int, input().split())
        if (N[s-1] != 0) and (f[s-1] == 0):
            print(-1)
            return 0
        elif (f[s-1] == 1) and (N[s-1] == c):
            pass
        elif (f[s-1] == 1):
            print(-1)
            return 0
        else:
            N[s-1] = c
            f[s-1] = 1
    if sum(N) == 0:
        print(-1)
    else:
        print(''.join(map(str, N)))


    return 0
if __name__ == '__main__':
    main()