def che(x):
    if x == -1:
        return 0
    return x


def main():
    N, M = map(int, input().split(' '))
    result = [-1 for _ in range(N)]
    flag = True
    for _ in range(M):
        a, b = map(int, input().split(' '))
        a = a - 1
        if result[a] != -1 or (a == 0 and b == 0):
            if result[a] != b:
                flag = False
                break
        result[a] = b
    result = [str(che(i)) for i in result]
    if flag or len(result) == 1:
        print(''.join(result))
    else:
        print(-1)


if __name__ == '__main__':
    main()
