def main():
    N, M = map(int, input().split())
    l = [-1] * N
    for i in range(M):
        s, c = map(int, input().split())
        if l[s-1] == -1 or l[s-1] == c:
            l[s-1] = c
        else:
            print('-1')
            return
    l = [0 if i == -1 else i for i in l]
    if N > 1 and l[0] == 0:
        print('-1')
        return
    print(''.join(str(i) for i in l))
main()
