Problem: There is a computer network consisting of n nodes numbered 1 through n. There are links in the network that connect pairs of nodes. A pair of nodes may have multiple links between them, but no node has a link to itself.

Each link supports unlimited bandwidth (in either direction), however a link may only transmit in a single direction at any given time. The cost of sending data across a link is proportional to the square of the bandwidth. Specifically, each link has a positive weight, and the cost of sending data across the link is the weight times the square of the bandwidth.

The network is connected (there is a series of links from any node to any other node), and furthermore designed to remain connected in the event of any single node failure.

You needed to send data from node 1 to node n at a bandwidth of some positive number k. That is, you wish to assign a bandwidth to each link so that the bandwidth into a node minus the bandwidth out of a node is  - k for node 1, k for node n, and 0 for all other nodes. The individual bandwidths do not need to be integers.

Wishing to minimize the total cost, you drew a diagram of the network, then gave the task to an intern to solve. The intern claimed to have solved the task and written the optimal bandwidths on your diagram, but then spilled coffee on it, rendering much of it unreadable (including parts of the original diagram, and the value of k).

From the information available, determine if the intern's solution may have been optimal. That is, determine if there exists a valid network, total bandwidth, and optimal solution which is a superset of the given information. Furthermore, determine the efficiency of the intern's solution (if possible), where efficiency is defined as total cost divided by total bandwidth.

Input

Input will begin with two integers n and m (2 ≤ n ≤ 200000; 0 ≤ m ≤ 200000), the number of nodes and number of known links in the network, respectively. Following this are m lines with four integers each: f, t, w, b (1 ≤ f ≤ n; 1 ≤ t ≤ n; f ≠ t; 1 ≤ w ≤ 100; 0 ≤ b ≤ 100). This indicates there is a link between nodes f and t with weight w and carrying b bandwidth. The direction of bandwidth is from f to t.

Output

If the intern's solution is definitely not optimal, print "BAD x", where x is the first link in the input that violates the optimality of the solution. If the intern's solution may be optimal, print the efficiency of the solution if it can be determined rounded to the nearest integer, otherwise print "UNKNOWN".

Examples

Input

4 5
1 2 1 2
1 3 4 1
2 3 2 1
2 4 4 1
3 4 1 2


Output

6


Input

5 5
2 3 1 1
3 4 1 1
4 2 1 1
1 5 1 1
1 5 100 100


Output

BAD 3


Input

6 4
1 3 31 41
1 5 59 26
2 6 53 58
4 6 97 93


Output

UNKNOWN


Input

7 5
1 7 2 1
2 3 1 1
4 5 1 0
6 1 10 0
1 3 1 1


Output

BAD 4

Note

Although the known weights and bandwidths happen to always be integers, the weights and bandwidths of the remaining links are not restricted to integers.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, const T2 &y) {
  if (y < x) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, const T2 &y) {
  if (x < y) x = y;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &b) {
  for (auto &k : b) os << k << ' ';
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &b) {
  for (auto &k : b) is >> k;
  return is;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 200100;
const long long INF = 1e18 + 228;
struct edge {
  long long id;
  long long to;
  long long cost;
  long long flow;
  edge(long long _id, long long _to, long long _cost, long long _flow) {
    id = _id;
    to = _to;
    cost = _cost;
    flow = _flow;
  }
};
vector<edge> g[N];
long long phi[N];
long long used[N];
bool ok;
long long mid;
long long minphi;
long long maxphi;
vector<long long> cur;
void dfs(long long v) {
  cur.push_back(v);
  used[v] = 1;
  maxe(maxphi, phi[v]);
  mine(minphi, phi[v]);
  for (auto [id, to, cost, flow] : g[v]) {
    if (id < mid) {
      long long must = phi[v] + flow * cost;
      if (!used[to]) {
        phi[to] = must;
        dfs(to);
      }
      ok &= phi[to] == must;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    long long f, t, w, b;
    cin >> f >> t >> w >> b;
    --f, --t;
    g[f].push_back(edge(i, t, w, b));
    g[t].push_back(edge(i, f, w, -b));
  }
  long long L = 0;
  long long R = m + 1;
  long long U = INF;
  while (R - L > 1) {
    ok = 1;
    mid = (L + R) / 2;
    memset(used, 0, sizeof(used));
    U = INF;
    for (long long i = 0; i < n && ok; ++i) {
      if (used[i]) continue;
      phi[i] = 0;
      maxphi = -INF;
      minphi = INF;
      cur.clear();
      dfs(i);
      ok &= maxphi - minphi < U;
      if (i == 0 && used[n - 1]) {
        U = phi[n - 1];
      }
      if (i == 0) {
        for (auto &v : cur) {
          ok &= v == 0 || phi[v] > 0;
        }
      }
      if (used[n - 1] == 1) {
        used[n - 1]++;
        for (auto &v : cur) {
          ok &= v == n - 1 || phi[v] < phi[n - 1];
        }
      }
    }
    if (ok)
      L = mid;
    else
      R = mid;
  }
  if (L < m) {
    cout << "BAD " << L + 1 << '\n';
    return 0;
  }
  if (U == INF) {
    cout << "UNKNOWN\n";
  } else {
    cout << U << '\n';
  }
}