import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    from collections import defaultdict
    d = defaultdict(int)
    N, M, *sc = map(int, read().split())
    ans = [0] * N
    sc = iter(sc)
    for i,s in zip(sc,sc):
        if N != 1 and i == 1 and s == 0:
            print(-1)
            break
        elif d[i] == 0 or d[i] == s:
            d[i] = s
            ans[i-1] = s
        else:
            print(-1)
            break
    else:
        if all([i == 0 for i in ans]):
            print('-1')
        elif ans[0] == 0:
            ans[0] = 1
        print(''.join(map(str,ans)))
    return
if __name__ == '__main__':
    main()

