#ABC157C
def main():
    import sys
    N, M = map(int, sys.stdin.readline().split())
    T = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    #print(T)
    flag = True
    ans = [-1 for _ in range(N)]
    for i in range(M):
        idx = T[i][0]-1
        v = T[i][1]
        if ans[idx] ==-1 or ans[idx] ==v:
            ans[idx] = v
        else:
            flag = False
            break
    if ans[0] ==-1 or ans[0]==0:
        flag = False
    else:
        for i in range(N):
            if ans[i] ==-1:
                ans[i] =0
        ans = list(map(str, ans))
        ans = ''.join(ans)
    if flag == False:
        print(-1)
    else:
        print(ans)
    
        
if __name__=='__main__':
    main()