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