#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UF {
  vector<Pi> data;
  UF(int n):data(n, Pi(-1, 0)){}
  Pi find(int x) {
    //cout<<x<<" "<<data[x].first<<" "<<data[x].second<<endl;
    if(data[x].first < 0) return Pi(x, 0);
    Pi p = find(data[x].first);
    //cout<<p.first<<" "<<p.second<<endl;
    data[x].first = p.first;
    data[x].second += p.second;
    return data[x];//Pi(p.first, data[x].second);
  }
  void unite(int a, int b, int w) {
    int x = find(a).first, y = find(b).first;
    if(x == y) return;
    if(data[x].first > data[y].first) swap(x, y), swap(a, b), w = -w;
    w += data[a].second-data[b].second;
    data[x].first += data[y].first;
    data[y].first = x;
    data[y].second += w;
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  while(cin >> N >> M, N || M) {
    UF uf(N);
    rep(i, M) {
      //cout << i << endl;
      char c; int a, b, w;
      cin >> c >> a >> b;
      --a, --b;
      if(c == '!') {
	cin >> w;
	uf.unite(a, b, w);
      } else if(c == '?') {
	Pi x = uf.find(a), y = uf.find(b);
	if(x.first != y.first) {
	  cout << "UNKNOWN" << endl;
	} else {
	  cout << y.second - x.second << endl;
	}
      }
    }
  }

  return 0;
}