N, M = map(int, input().split())
ss, cs = [], []
for i in range(M):
    s, c = map(int, input().split())
    ss.append(s)
    cs.append(c)


def main():
    result = ["-1"] * N
    for s, c in zip(ss, cs):
        if s > N:
            continue
        elif s == 1 and c == 0:
            print("-1")
            return
        elif result[s-1] != str(c) and result[s-1] != "-1":
            print("-1")
            return
        else:
            result[s-1] = str(c)
    
    if result[0] == "-1":
        result[0] = "1"
    
    for i in range(1, N):
        if result[i] == "-1":
            result[i] = "0"

    result_string = "".join(result)
    if int(result_string) >= 0 and len(result_string) == N:
        print(result_string)
    else:
        print("-1")



if __name__ == "__main__":
    main()
