n, m = map(int, input().split())
s_list = []
c_list = []

is_err = False
def has_err(seq):
    if 1 != len(set(seq)):
        return True
    else:
        return False

for _ in range(m):
    s, c = map(int, input().split())
    s_list.append(s)
    c_list.append(c)
    if (s, c) == (1, 0):
        is_err = True
    if s in s_list:
        ix_list = [i for i, x in enumerate(s_list) if x == s]
        if has_err([x for i, x in enumerate(c_list) if i in ix_list]):
            is_err = True

if is_err:
    print('-1')
    quit()

if (n, m) == (1, 0):
    print(0)
    quit()

int_dict = {}
for s, c in zip(s_list, c_list):
    int_dict.update({"{}".format(s):c})

for i in range(1,n+1):
    if str(i) not in int_dict.keys() and i == 1:
        int_dict.update({"{}".format(i):1})
    elif str(i) not in int_dict.keys() and i != 1:
        int_dict.update({"{}".format(i):0})

ans = 0
for k, v in int_dict.items():
    ans += 10**(n-int(k))*v

print(ans)