
def main():
    N, M = [int(x) for x in input().split()]
    expected_num_ary = [0] * N

    digit = []
    value = []
    for _ in range(M):
        d, v = [int(x) for x in input().split()]
        if d > N:
            print("-1")
            return
        expected_num_ary[d - 1] = v

    num_str = ""
    for num in expected_num_ary:
        num_str += str(num)

    if num_str.lstrip("0") == "" and N == 1:
        print(0)
    else:
        print(-1 if N != len(num_str.lstrip("0")) else num_str)


if __name__ == '__main__':
    main()