N,M = map(int,input().split())
sc_s = list(list(map(int,input().split())) for _ in range(M)) 
sc_s.sort()
answer = ['0']*N
def solve():
    for i in range(1,len(sc_s)):
        if sc_s[i][0] == sc_s[i-1][0] and sc_s[i][1] != sc_s[i-1][1]:
            return ['-1']
    for i in range(len(sc_s)):
        if sc_s[i] == [1,0]:
            return ['-1']
        answer[sc_s[i][0]-1] = str(sc_s[i][1])
    if answer[0] == '0':
        answer[0] = '1'
    return answer

print(''.join(solve()))
    
        