import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    while (solve) {}
}

bool solve() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    if (N == 0) return false;

    auto uf = new UnionFind(N);

    while (M--) {
        auto q = readln.split;
        auto a = q[1].to!int - 1;
        auto b = q[2].to!int - 1;
        if (q[0] == "!") {
            auto w = q[3].to!int;
            uf.unite(a, b, w);
        } else {
            if (uf.find(a) != uf.find(b)) {
                writeln("UNKNOWN");
            } else {
                writeln(uf.weight[b] - uf.weight[a]);
            }
        }
    }

    return true;
}


class UnionFind {
    int N;
    int[] table;
    int[] weight;
    int[][] group;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        weight = new int[](N);
        group = N.iota.map!(i => [i]).array;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y, int diff) {
        int ox = x;
        int oy = y;
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (table[x] > table[y]) {
            swap(x, y);
            swap(ox, oy);
            diff *= -1;
        }

        int nw = weight[ox] + diff;
        int ndiff = nw - weight[oy];
        foreach (i; group[y]) weight[i] += ndiff;
        foreach (i; group[y]) group[x] ~= i;
        group[y] = [];

        table[x] += table[y];
        table[y] = x;
    }
}

