def main():
    n, m = map(int, input().split())
    sc_list = [list(input().split()) for _ in range(m)]
    ans_list = []
    for s, c in sc_list:
        if s == "1" and c == 0 and n > 1:
            print(-1)
            return
        if s == "1" and c == 0 and n == 0:
            print(0)
            return
    for i in range(10 ** (n - 1), 10 ** n):
        i_list = list(str(i))
        if all([i_list[int(s) - 1] == c for s, c in sc_list]):
            ans_list.append(i)
    if not ans_list:
        print(-1)
    else:
        print(min(ans_list))
main()