def main():
    n, m = [int(e) for e in input().split()]
    if m == 0:
        print(10**(n - 1))
        exit()

    S, C = zip(*[[int(e) for e in input().split()] for i in range(m)])

    ans = 0
    D = {}
    for si, ci in zip(S, C):
        if D.get(si) == ci:
            continue

        if D.get(si) is not None:
            print(-1)
            exit()

        ans += 10**(n - si) * ci
        D[si] = ci

    if len(str(ans)) != n:
        print(-1)
        exit()

    print(ans)

if __name__ == "__main__":
    main()
