n, m = input().split()
sc_dic = {}
ans = 0
for i in range(int(m)):
    s, c = input().split()
    if s in sc_dic:
        if c != sc_dic[s]: ans = -1
    if s == '1' and c == '0' and n != '1': ans = -1
    sc_dic[s] = c
if ans == -1:
    print(ans)
else:
    for k, v in sc_dic.items():
        ans += int(v) * (10 ** (int(n) - int(k)))
    print(ans)