class UnionFind
	def initialize
		@node = []
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@dw = 0
		end

		attr_accessor :parent, :dw
	end

	def union(x, y, dw0)
		u, dw1 = root_and_dw(@node[x] ||= Node.new(x))
		v, dw2 = root_and_dw(@node[y] ||= Node.new(y))
		return if u == v
		v.parent, v.dw = u, dw0 + dw1 - dw2
	end

	def weight_diff(x, y)
		return nil unless u = @node[x]
		return nil unless v = @node[y]
		r1, dw1 = root_and_dw(u)
		r2, dw2 = root_and_dw(v)
		return nil if r1 != r2
		dw2 - dw1
	end
end

def root_and_dw(u)
	return [u, 0] if u.parent == u
	path = [u]
	path << path[-1].parent until path[-1].parent == path[-1]
	root = path[-1]
	dw = 0
	until path.empty?
		v = path.pop
		v.parent, v.dw = root, dw += v.dw
	end
	[root, u.dw]
end	


loop do
	n, m = gets.split.map &:to_i
	break if n == 0
	uf = UnionFind.new

	m.times do
		q, a, b, dw = gets.chomp.split
		a, b = a.to_i, b.to_i
		if q == ?!
			uf.union(a, b, dw.to_i)
		else
			dw = uf.weight_diff(a, b)
			puts dw ? dw : 'UNKNOWN'
		end
	end
end