import scala.annotation.tailrec
import scala.io.StdIn._

object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && m == 0) return
    val union = new DiffUnionFind(n)
    for (_ ← 0 until m) {
      readLine.trim.split(' ') match {
        case Array("!", a, b, w) ⇒ union.setRelation(a.toInt - 1, b.toInt - 1, w.toInt)
        case Array("?", a, b) ⇒
          union.findDiff(a.toInt - 1, b.toInt - 1) match {
            case Some(d) ⇒ println(d)
            case None ⇒ println("UNKNOWN")
          }
        case _ ⇒ ???
      }
    }
    solve()
  }
}


class DiffUnionFind(val size: Int) {
  private val parent = Array.fill(size){-1}
  private val diff = Array.fill(size){0L}
  private def find(a: Int): (Int, Long) = {
    if (parent(a) < 0) {
      (a, 0L)
    }else {
      val (p, d) = find(parent(a))
      parent(a) = p
      diff(a) += d
      (p, diff(a))
    }
  }
  def setRelation(a: Int, b: Int, w: Int): Boolean = {
    val (ar, ad) = find(a)
    val (br, bd) = find(b)
    if (ar != br) {
      if (parent(ar) < parent(br)) {
        parent(ar) += parent(br)
        parent(br) = ar
        diff(br) = ad + w - bd
      }else {
        parent(br) += parent(ar)
        parent(ar) = br
        diff(ar) = bd - ad - w
      }
    }
    ar != br || ad + w == bd
  }
  def findDiff(a: Int, b: Int): Option[Long] = {
    val (ar, ad) = find(a)
    val (br, bd) = find(b)
    if (ar == br) Some(bd - ad)
    else None
  }
}
