def resolve():
    N,M = list(map(int, input().split(' ')))
    K = [-1] * N
    for i in range(M):
        s, c = list(map(int, input().split(' ')))
        if K[s-1] != -1 and K[s-1] != c:
            print('-1')
            return
        K[s-1] = c
    if K[0] == 0:
        print('-1')
        return
    ans = ""
    for i in range(N):
        if i==0 and K[i]==-1:
            ans += '1'
        elif K[i] == -1:
            ans += '0'
        else:
            ans += str(K[i])
    print(ans)

resolve()