import sys
n, m = map(int, input().split())
s_c_dic = {}

flag = False
for _ in range(1, m+1):
    one, two = map(int, input().split())
    if one in list(s_c_dic.keys()):
        if two == s_c_dic[one]:
            pass
        else:
            flag = True
            break
    else:
        s_c_dic[one] = two

if flag:
    print(-1)
    sys.exit()

if 1 in list(s_c_dic.keys()):
    if n == 1 and s_c_dic[1] == 0:
        print(0)
        sys.exit()
        
    if s_c_dic[1] == 0:
        print(-1)
        sys.exit()

result_num = []
for i in range(1, n+1):
    if i == 1 and i not in list(s_c_dic.keys()):
        result_num.append(1)
    else:
        if i not in list(s_c_dic.keys()):
            result_num.append(0)
        else:
            result_num.append(s_c_dic[i])

result = result_num[0]
for i in range(1, len(result_num)):
    result *= 10
    result += result_num[i]
print(result)