def main():
    N,M = map(int, input().split())
    m = ["0"]*N
    for _ in range(M):
        s,c = input().split()
        # 左からsけた目がc
        m[N-int(s)] = c
    if N==1:
        print("".join(m[::-1]))
    else:
        if m[0]=="0":
            print("-1")
        else:
            print("".join(m[::-1]))

main()
