#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef pair<int,int> P;

struct UnionFind{
	// (parent, offset_from_parent)
	vector<P> uf;
	
	UnionFind(int N){
		for(int i=0 ; i < N ; i++ ){
			uf.push_back( P(i, 0) );
		}
	}
	
	// Returns (root, offset_from_root> while compressing the path.
	P find(int x){
		if( uf[x].first != x ){
			P p = find(uf[x].first);
			uf[x] = P(p.first, uf[x].second + p.second);
		}
		return uf[x];
	}
	
	void unite(int a, int b, int w){ // [a] + w = [b]
		P aa = find(a); // [aa.first] + aa.second = [a]
		P bb = find(b); // [bb.first] + bb.second = [b]
		// Then, [bb.first] + (bb.second - w - aa.second) = [aa.first]
		if( aa.first != bb.first ){
			uf[aa.first] = P(bb.first, bb.second - w - aa.second);
		}
	}
};

int main(){
	int N, M;
	while( cin >> N >> M , N || M ){
		UnionFind uf(N);
		
		for(int i=0 ; i < M ; i++ ){
			char q;
			cin >> q;
			if( q == '!' ){
				int a, b, w;
				cin >> a >> b >> w;
				a--; b--;
				uf.unite(a, b, w);
			}else if( q == '?' ){
				int a, b;
				cin >> a >> b;
				a--; b--;
				P aa = uf.find(a);
				P bb = uf.find(b);
				if( aa.first != bb.first ){
					cout << "UNKNOWN" << endl;
				}else{
					cout << bb.second - aa.second << endl;
				}
			}
		}
	}
}