#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define MAX_N	(100000)

/* typedef */

/* global variables */

int uft[MAX_N + 1], dfs[MAX_N + 1], lvls[MAX_N + 1];

/* subroutines */

int rootd(int k, int& d) {
  int rk = k;
  d = 0;
  
  while (rk != uft[rk]) {
    d += dfs[rk];
    rk = uft[rk];
  }

  return rk;
}

/* main */

int main() {
  for (;;) {
    int n, m;
    cin >> n >> m;
    if ((n | m) == 0) break;

    for (int i = 1; i <= n; i++) {
      uft[i] = i;
      dfs[i] = 0;
      lvls[i] = 1;
    }

    for (int i = 0; i < m; i++) {
      char op;
      int a, b;

      cin >> op >> a >> b;

      int ra, rb, da, db;
      ra = rootd(a, da);
      rb = rootd(b, db);
    
      if (op == '!') {
	int w;
	cin >> w;
	int rd = w + db - da;

	if (ra == rb) {
	  if (rd == 0) continue;
	  cout << "Error" << endl;
	  exit(0);
	}

	if (lvls[ra] <= lvls[rb]) {
	  uft[ra] = rb;
	  dfs[ra] = rd;
	  if (lvls[ra] == lvls[rb]) lvls[rb]++;
	}
	else {
	  uft[rb] = ra;
	  dfs[rb] = -rd;
	}
      }
      else {
	if (ra != rb)
	  cout << "UNKNOWN" << endl;
	else {
	  int d = da - db;
	  cout << d << endl;
	}
      }
    }
  }

  return 0;
}