
def main():
    n, m = list(map(int, input().split()))
    sc = {}
    answer = ["0" for i in range(n)]

    for i in range(m):
        s, c = list(input().split())
        if s in sc and c != sc[s]:
            print("-1")
            return
        sc[s] = c
        answer[int(s) - 1] = c
    po = "".join(answer)
    if str(int(po)) != po:
        print("-1")
        return
    print(po)

main()