#include <iostream>
using namespace std;

int n,q;
int p[100010] = {0},r[100010] = {0};
int diff_weight[100010] = {0};

void init(int N){
	for(int i=0;i<=N;++i){
		p[i] = i;
		diff_weight[i] = 0;
		r[i] = 0;
	}
}

int root(int a){
	if(p[a] == a) return a;
	else{
		int r = root(p[a]);
		diff_weight[a] += diff_weight[p[a]];
		return (p[a] = r);
	}
}

bool is_same_set(int a,int b){
	return root(a) == root(b);
}

int weight(int a){
	root(a);
	return diff_weight[a];
}

int diff(int a, int b){
	return weight(b) - weight(a);
}

void unite(int a, int b, int w){
	w += weight(a);
	w -= weight(b);
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		int t = a;
		a = b;
		b = t;
		w = -w;
	}
	//}else{
	if(r[a] == r[b]) r[a]++;
	p[b] = a;
	diff_weight[b] = w;
}

int main(){
	while(cin >> n >> q && n>0){;
		init(n);
		for(int i=0;i<q;i++){
			char c;
			int w,a,b;
			cin >> c;
			if(c=='!'){
				cin >> a >> b >> w;
				unite(a,b,w);
			}else{
				cin >> a >> b;
				if(is_same_set(a,b)) cout << diff(a,b) << endl;
				else cout << "UNKNOWN" << endl;
			}
		}
	}
}
