def main():
    N, M = map(int, input().split(' '))
    s = []
    c = []
    for i in range(M):
        si, ci = map(int, input().split(' '))
        s.append(si)
        c.append(ci)
    
    ans = [0]*N
    flag = False
    for i in range(M):
        if ans[s[i]-1] == 0:
            ans[s[i]-1] = c[i]
        elif c[i] == 0:
            ans[s[i]] = c[i]
        elif ans[s[i]-1] == c[i]:
            pass
        else:
            flag = True
    
    if flag:
        print("-1")
    elif sum(ans) == 0:
        print("-1")
    else:
        for i in range(N):
            print(ans[i], end='')
        print('')    

if __name__ == '__main__':
    main()