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_num = ["-1"] * N
    for (s, c) in zip(ss, cs):
        if s > N:
            continue
        elif s == 1 and c == 0:  # 一番左側の桁が0ならだめ
            print("-1")
            return
        elif result_num[s-1] in ["-1", str(c)]:
            result_num[s-1] = str(c)
        else:
            print("-1")
            return

    if result_num[0] == "-1":
        result_num[0] = "1"
    
    for i in range(1, N):
        if result_num[i] == "-1":
            result_num[i] = "0"
    result_string = "".join(result_num)
    print(result_string)
    
    
if __name__ == "__main__":
    main()