def main():
    n, m = map(int, raw_input().split())
    aa = [None] * n
    for _ in xrange(m):
        s, c = raw_input().split()
        s = int(s) - 1
        if aa[s] is not None and aa[s] != c:
            print '-1'
            return
        aa[s] = c
    for i, a in enumerate(aa):
        if a is None:
            aa[i] = '0'
    if aa[0] is None:
        aa[0] = '1'
    if n == 1:
        print aa[0]
        return
    if aa[0] == '0':
        print -1
    else:
        print ''.join(aa)

main()
