def main():
    N,M = map(int, input().split())
    x = ["0"]*N
    hfixed = [False]*N
    flag = False
    for _ in range(M):
        s,c = input().split()
        # 左からsけた目がc
        idx = int(s)-1
        if hfixed[idx] and x[idx]!=c:
            flag = True
            break
        else:
            hfixed[idx] = True
            x[idx] = c
            
    if flag:
        print("-1")
    else:
        if N==1:
            print("".join(x))
        else:
            if x[0]=="0":
                if hfixed:
                    print("-1")
                else:
                    x[0] = "1"
                    print("".join(x))
            else:
                print("".join(x))

main()
