#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

LL a[110000];
int f[110000];

int gf(int x){
	int y=f[x];
	if (x==y) return x;
	f[x]=gf(y); a[x]+=a[y];
	return f[x];
}

int main(){
	int N,M,i;
	while (scanf("%d%d",&N,&M),N || M){
		for (i=1;i<=N;i++){
			f[i]=i; a[i]=0;
		}
		while (M--){
			char s[110];
			int u,v,d,x,y;
			scanf("%s",s);
			if (*s=='!'){
				scanf("%d%d%d",&u,&v,&d);
				x=gf(u); y=gf(v);
				if (x==y) continue;
				a[y]=a[u]-a[v]+d; f[y]=x;
			}else{
				scanf("%d%d",&u,&v);
				x=gf(u); y=gf(v);
				printf(x==y?"%lld\n":"UNKNOWN\n",a[v]-a[u]);
			}
		}
	}
}