#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long int lli;

class exUnionFindTree{
public:
    vector<int> v;
    vector<int> rank;
    vector<lli> diff;
    
    exUnionFindTree(int n){
        v = vector<int>(n);
        rank = vector<int>(n, 0);
        diff = vector<lli>(n, 0);
        for(int i=0; i<n; i++) v[i]=i;
    }
    int Find(int x){
        return _find(x).first;
    }
    pair<int, lli> _find(int x){
        if(v[x] != x){
            pair<int, lli> ret = _find(v[x]);
            v[x] = ret.first;
            diff[x] += ret.second;
        }
        return make_pair(v[x], diff[x]);
    }
    void Union(int a, int b, lli w){
        int ra = Find(a);
        int rb = Find(b);
        if(ra == rb) return;
        if(rank[ra] < rank[rb]){
            v[ra] = rb;
            diff[ra] = diff[b] -diff[a] -w;
        }else{
            v[rb] = ra;
            diff[rb] = diff[a] -diff[b] +w;
            if(rank[ra] == rank[rb]){
                rank[ra]++;
            }
        }
    }
};

int main(){
	while(1){
		int n,m;
		cin >> n >> m;
		if(n==0) break;
		
		exUnionFindTree uft(n+1);
		for(int i=0; i<m; i++){
			char c;
			cin >> c;
			if(c=='?'){
				int a,b;
				cin >> a >> b;
				if(uft.Find(a) == uft.Find(b)){
					cout << uft.diff[b] -uft.diff[a] << endl;
				}else{
					cout << "UNKNOWN" << endl;
				}
			}else{
				int a,b;
				lli diff;
				cin >> a >> b >> diff;
				uft.Union(a, b, diff);
			}
		}
	}
	return 0;
}
