import sys
input = sys.stdin.readline

def main():
    N , M = map(int, input().split())
    sc = {}
    ans = 0

    for _ in range(M):
        s, c = map(int, input().split())

        if s == 1 and c == 0:
            print(-1)
            quit()

        if s in sc:
            if c != sc[s]:
                print(-1)
                quit()
        else:
            sc[s] = c
            ans += c * (10 ** (N - s))

    if ans < 10 ** (N-1):
        ans += 10 ** (N - 1)

    print(ans)



if __name__ == "__main__":
    main()
