#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_N 100005
using namespace std;
typedef pair<int,int> P;
P par[MAX_N];

void init(int n){
  for(int i=0;i<n;i++)
    par[i]=P(i,0);
}

P find(int x){
  if(par[x].first==x)return P(x,0);
  P r=find(par[x].first);
  return par[x]=P(r.first,par[x].second+r.second);
}

void unite(int x,int y,int cost){
  P r1=find(x);
  P r2=find(y);
  if(r1.first==r2.first)return;
  par[r1.first]=P(r2.first,r2.second-r1.second+cost);
}

bool same(int x,int y){return find(x).first==find(y).first;}

int n,m,a,b,cost;
char c;

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    init(n);
    rep(i,m){
      cin>>c>>a>>b;
      if(c=='!'){
	cin>>cost;
	unite(b-1,a-1,cost);
      }else{
	if(!same(a-1,b-1))cout<<"UNKNOWN"<<endl;
	else cout<<find(b-1).second-find(a-1).second<<endl;
      }
    }
  }
  return 0;
}