#include
#include
#include
#include
using namespace std;
typedef long long int lli;
const int MAXN = 1e5+10;
#define INF 0x3f3f3f3f
#define M(a) memset(a,0,sizeof(a))
#define lson root<<1
#define rson root<<1|1
int val[MAXN],fa[MAXN],dep[MAXN],siz[MAXN],id[MAXN],top[MAXN],ran[MAXN],son[MAXN];
typedef struct ee
{
int u,v;
int next;
ee(){u=v=next=0;}
ee(int uu,int vv,int va)
{
u=uu;
v=vv;
next=va;
}
}ee;
ee edge[MAXN*2];
int head[MAXN],cnt;
int num,n;
typedef struct node
{
int l,r;
int val;
int type;
}node;
node Btree[MAXN*4];
vector chain;
vector sum[MAXN];
void addedge(int u,int v)
{
edge[cnt].u=u;
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void dfs1(int x,int f,int d)
{
dep[x]=d;
siz[x]=1;
son[x]=0;
fa[x]=f;
for(int i=head[x];i!=-1;i=edge[i].next)
{
int tmp=edge[i].v;
if(tmp==f) continue;
dfs1(tmp,x,d+1);
siz[x]+=siz[tmp];
if(siz[son[x]]r) return;
Btree[root].l=l;
Btree[root].r=r;
Btree[root].val=0;
Btree[root].type=0;
if(l==r)
{
Btree[root].type=l;
return;
}
int mid=(l+r)/2;
build(l,mid,root*2);
build(mid+1,r,root*2+1);
pushup(root);
}
void updateone(int root,int index,int val)
{
if(index==Btree[root].l&&index==Btree[root].r)
{
Btree[root].val+=val;
return;
}
int mid=(Btree[root].l+Btree[root].r)/2;
if(index<=mid)
updateone(root*2,index,val);
else
updateone(root*2+1,index,val);
pushup(root);
}
void solve1(int a,int b,int c)
{
if(dep[top[a]]id[b]) swap(a,b);
chain.push_back(ee(id[a],id[b],c));
}
int res[MAXN];
int main()
{
int q,t;
while(scanf("%d%d",&n,&q),n+q)
{
num=0;
M(son);
M(Btree); //!! 因为maxv=0的时候Btree保存的就是前面一组数据的树
cnt=0;
chain.clear();
for(int i=1;i<=n+1;i++) sum[i].clear(); //!!!!n+1
memset(head,-1,sizeof(head));
for(int i=1;i