#include<iostream>
using namespace std;
int parent[1<<17],myrank[1<<17],weight[1<<17];
int root(int x)
{
	if(parent[x]==x)return x;
	else
	{
		int r=root(parent[x]);
		weight[x]+=weight[parent[x]];
		return parent[x]=r;
	}
}
int get_weight(int x)
{
	root(x);
	return weight[x];
}
bool issame(int x,int y)
{
	return root(x)==root(y);
}
void diff(int x,int y)
{
	if(!issame(x,y))
	{
		cout<<"UNKNOWN"<<endl;
	}
	else cout<<get_weight(y)-get_weight(x)<<endl;
}
void mymerge(int x,int y,int w)
{
	w+=get_weight(x)-get_weight(y);
	x=root(x);y=root(y);
	if(myrank[x]<myrank[y])swap(x,y),w*=-1;
	if(myrank[x]==myrank[y])myrank[x]++;
	parent[y]=x;
	weight[y]=w;
}
int main()
{
	int n,m;
	while(cin>>n>>m,n)
	{
		for(int i=0;i++<n;)parent[i]=i,myrank[i]=0,weight[i]=0;
		for(int i=0;i<m;i++)
		{
			char c;cin>>c;
			if(c=='!')
			{
				int a,b,w;cin>>a>>b>>w;
				mymerge(a,b,w);
			}
			else
			{
				int a,b;cin>>a>>b;
				diff(a,b);
			}
		}
	}
}

