def resolve():
    N, M = map(int, input().split())

    checked = [False] * N
    ans = ['0'] * N

    for i in range(M):
        ss, cc = input().split()
        index = int(ss) - 1

        if checked[index] and ans[index] != cc:
            print(-1)
            return

        ans[index] = cc
        checked[index] = True

    int_ans = int(''.join(ans))

    diff = len(list(str(int_ans))) - N

    if diff == 0:
        print(int_ans)
        return

    if diff > 0:
        ans = int(''.join(ans))
        if diff == 2:
            print('10' + str(ans))
            return
        if diff == 1:
            print('1' + str(ans))
            return

    print(-1)
    
resolve()