BaoBao just learned how to use a data structure called link-cut tree to find cycles in a graph and decided to give it a try. BaoBao is given an undirected graph with nnn vertices and mmm edges, where the length of the iii-th edge equals 2i2^i2i. She needs to find a simple cycle with the smallest length. A simple cycle is a subgraph of the original graph containing kkk vertices a1,a2,,aka_1, a_2, cdots, a_ka1,a2,,ak and kkk edges such that for all 1≤i≤k1 le i le k1≤i≤k there is an edge connecting vertices aia_iai and a+1a_{ + 1}a+1 in the subgraph. The length of a simple cycle is the total length of the edges in the cycle.
BaoBao just learned how to use a data structure called link-cut tree to find cycles in a graph and decided to give it a try. BaoBao is given an undirected graph with nnn vertices and mmm edges, where the length of the iii-th edge equals 2i2^i2i. She needs to find a simple cycle with the smallest length. A simple cycle is a subgraph of the original graph containing kkk (3≤k≤n3 le k le n3≤k≤n) vertices a1,a2,⋯ ,aka_1, a_2, cdots, a_ka1,a2,⋯,ak and kkk edges such that for all 1≤i≤k1 le i le k1≤i≤k there is an edge connecting vertices aia_iai and a(imod k)+1a_{(i mod k) + 1}a(imodk)+1 in the subgraph. The length of a simple cycle is the total length of the edges in the cycle.