#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> P;

struct UnionFind {
	vector<int> par;
	vector<int> d;
	int cnt;
	UnionFind(int size_) : par(size_, -1), d(size_), cnt(size_) {}
	void unite(int x, int y, int w) {
		P px = find(x), py = find(y);
		if(px.first != py.first) {
			if(par[py.first] < par[px.first]) swap(px, py), w *= -1;
			par[px.first] += par[py.first];
			par[py.first] = px.first;
			d[py.first] = px.second - py.second - w;
			cnt--;
		}
	}
	bool same(int x, int y) {
		return find(x).first == find(y).first;
	}
	P find(int x) {
		if(par[x] < 0) return P(x, 0);
		P res = find(par[x]);
		par[x] = res.first;
		d[x] += res.second;
		return P(par[x], d[x]);
	}
	int size() { return cnt; }
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	while(cin >> N >> M, N | M) {
		UnionFind uf(N);
		while(M--) {
			char c; int a, b, diff;
			cin >> c >> a >> b;
			a--, b--;
			if(c == '!') {
				cin >> diff;
				if(uf.same(a, b)) continue;
				uf.unite(a, b, diff);
			}
			else {
				if(uf.same(a, b)) {
					int w1 = uf.find(a).second, w2 = uf.find(b).second;
					cout << w1 - w2 << endl;
				}
				else {
					cout << "UNKNOWN" << endl;
				}
			}
		}
	}
}