#include <bits/stdc++.h>

using namespace std;

struct WeightedUnionFind
{
  vector< int > data, weight;

  WeightedUnionFind(int sz) : data(sz, -1), weight(sz, 0) {}

  void unite(int x, int y, int w)
  {
    auto a = find(x), b = find(y);
    if(data[a.first] > data[b.first]) {
      swap(a, b);
      w *= -1;
    }
    x = a.first, y = b.first;
    if(x == y) return;
    data[x] += data[y];
    data[y] = x;
    weight[y] = a.second - b.second - w;
  }

  pair< int, int > find(int k)
  {
    if(data[k] < 0) return (make_pair(k, 0));
    auto par = find(data[k]);
    data[k] = par.first;
    weight[k] = (par.second += weight[k]);
    return (par);
  }

  void diff(int a, int b)
  {
    if(find(a).first != find(b).first) cout << "UNKNOWN" << endl;
    else cout << weight[a] - weight[b] << endl;
  }
};

int main()
{
  int N, M;
  while(cin >> N >> M, N) {
    WeightedUnionFind tree(N);
    while(M--) {
      char A;
      int B, C, D;
      cin >> A >> B >> C;
      --B, --C;
      if(A == '!') {
        cin >> D;
        tree.unite(B, C, D);
      } else {
        tree.diff(B, C);
      }
    }
  }
}
