n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))
scd = {}
for i in range(m):
    if (sc[i][0] in scd.keys()):
        if (sc[i][1] != scd[sc[i][0]]):
            print('-1')
            break
    scd[sc[i][0]] = sc[i][1]
else:
    s = ['0' for i in range(n)]
    scdkey = list(scd.keys())
    for i in range(len(scd)):
        s[scdkey[i] - 1] = str(scd[scdkey[i]])
    if (len(s) > 1) & (s[0] == '0'):
        print('-1')
    else:
        st = ''.join(s)
        print(st)