Egor is a famous Russian singer, rapper, actor and blogger, and finally he decided to give a concert in the sunny Republic of Dagestan.

There are n cities in the republic, some of them are connected by m directed roads without any additional conditions. In other words, road system of Dagestan represents an arbitrary directed graph. Egor will arrive to the city 1, travel to the city n by roads along some path, give a concert and fly away.

As any famous artist, Egor has lots of haters and too annoying fans, so he can travel only by safe roads. There are two types of the roads in Dagestan, black and white: black roads are safe at night only, and white roads — in the morning. Before the trip Egor's manager's going to make a schedule: for each city he'll specify it's color, black or white, and then if during the trip they visit some city, the only time they can leave it is determined by the city's color: night, if it's black, and morning, if it's white. After creating the schedule Egor chooses an available path from 1 to n, and for security reasons it has to be the shortest possible.

Egor's manager likes Dagestan very much and wants to stay here as long as possible, so he asks you to make such schedule that there would be no path from 1 to n or the shortest path's length would be greatest possible.

A path is one city or a sequence of roads such that for every road (excluding the first one) the city this road goes from is equal to the city previous road goes into. Egor can move only along paths consisting of safe roads only. 

The path length is equal to the number of roads in it. The shortest path in a graph is a path with smallest length.

Input

The first line contains two integers n, m (1 ≤ n ≤ 500000, 0 ≤ m ≤ 500000) — the number of cities and the number of roads.

The i-th of next m lines contains three integers — u_i, v_i and t_i (1 ≤ u_i, v_i ≤ n, t_i ∈ \{0, 1\}) — numbers of cities connected by road and its type, respectively (0 — night road, 1 — morning road).

Output

In the first line output the length of the desired path (or -1, if it's possible to choose such schedule that there's no path from 1 to n).

In the second line output the desired schedule — a string of n digits, where i-th digit is 0, if the i-th city is a night one, and 1 if it's a morning one.

If there are multiple answers, print any.

Examples

Input


3 4
1 2 0
1 3 1
2 3 0
2 3 1


Output


2
011

Input


4 8
1 1 0
1 3 0
1 3 1
3 2 0
2 1 0
3 4 1
2 4 0
2 4 1


Output


3
1101

Input


5 10
1 2 0
1 3 1
1 4 0
2 3 0
2 3 1
2 5 0
3 4 0
3 4 1
4 2 1
4 5 0


Output


-1
11111

Note

For the first sample, if we paint city 1 white, the shortest path is 1 → 3. Otherwise, it's 1 → 2 → 3 regardless of other cities' colors.

For the second sample, we should paint city 3 black, and there are both black and white roads going from 2 to 4. Note that there can be a road connecting a city with itself.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using li = __int128;
using uli = unsigned __int128;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
void doReplace() {}
template <typename T, typename U, typename... Vs>
void doReplace(T& t, const U& u, Vs&&... vs) {
  t = u;
  doReplace(vs...);
}
template <typename T, typename... Us>
T minim(T& was, const T& cand, Us&&... us) {
  if (was > cand) {
    was = cand;
    doReplace(us...);
  }
  return was;
}
template <typename T, typename... Us>
T maxim(T& was, const T& cand, Us&&... us) {
  if (was < cand) {
    was = cand;
    doReplace(us...);
  }
  return was;
}
template <typename D>
D dPower(D base, ll exponent) {
  if (exponent < 0) {
    return dPower(1 / base, -exponent);
  }
  if (exponent == 0) {
    return 1;
  }
  if ((exponent & 1) == 1) {
    return dPower(base, exponent - 1) * base;
  } else {
    D res = dPower(base, exponent >> 1);
    return res * res;
  }
}
class NumberIterator : iterator<forward_iterator_tag, int> {
 public:
  int v;
  NumberIterator(int v) : v(v) {}
  operator int&() { return v; }
  int operator*() { return v; }
};
class range : pii {
 public:
  range(int begin, int end) : pii(begin, max(begin, end)) {}
  range(int n) : pii(0, max(0, n)) {}
  NumberIterator begin() { return first; }
  NumberIterator end() { return second; }
};
template <typename T>
class NeedFill {
  struct Fallback {
    int begin;
  };
  struct Derived : T, Fallback {};
  template <typename U, U>
  struct Check;
  typedef char Yes[1];
  typedef char No[2];
  template <typename U>
  static No& func(Check<int Fallback::*, &U::begin>*);
  template <typename U>
  static Yes& func(...);

 public:
  enum { value = sizeof(func<Derived>(0)) == sizeof(Yes) };
};
template <>
class NeedFill<int> {
 public:
  const static bool value = false;
};
template <>
class NeedFill<bool> {
 public:
  const static bool value = true;
};
template <>
class NeedFill<ll> {
 public:
  const static bool value = false;
};
template <>
class NeedFill<double> {
 public:
  const static bool value = false;
};
template <>
class NeedFill<char> {
 public:
  const static bool value = false;
};
template <typename T>
class arr {
  T* b;
  int n;
  void allocate(int sz) {
    n = sz;
    if (sz > 0) {
      b = (T*)(::operator new(sz * sizeof(T)));
    } else {
      b = nullptr;
    }
  }

 public:
  arr(int n = 0) {
    allocate(n);
    if (NeedFill<T>::value) {
      for (int i : range(n)) {
        ::new ((void*)(b + i)) T;
      }
    }
  }
  arr(int n, const T& init) {
    allocate(n);
    for (int i : range(n)) {
      ::new ((void*)(b + i)) T(init);
    }
  }
  arr(T* b, int n) : arr(b, b + n) {}
  arr(T* b, T* e) : b(b), n(e - b) {}
  arr(initializer_list<T> l) : arr(l.size()) {
    if (n > 0) {
      memcpy(b, l.begin(), n * sizeof(T));
    }
  }
  int size() const { return n; }
  T* begin() { return b; }
  const T* begin() const { return b; }
  T* end() { return b + n; }
  const T* end() const { return b + n; }
  arr<T> clone() const {
    arr<T> res(n);
    copy(b, b + n, res.begin());
    return res;
  }
  T& operator[](int at) { return b[at]; }
  const T& operator[](int at) const { return b[at]; }
  bool operator==(const arr& other) const {
    if (n != other.n) {
      return false;
    }
    for (int i : range(n)) {
      if (b[i] != other.b[i]) {
        return false;
      }
    }
    return true;
  }
  vector<T> view() { return vector<T>(b, b + n); }
};
void decreaseByOne() {}
template <typename T, class... Vs>
void decreaseByOne(arr<T>& array, Vs&... vs) {
  int n = array.size();
  for (int i : range(n)) {
    array[i]--;
  }
  decreaseByOne(vs...);
}
template <typename T>
class arr2d {
  T* b;
  int d1;
  int d2;
  int sz;
  void allocate(int n) {
    if (n > 0) {
      b = (T*)(::operator new(n * sizeof(T)));
    } else {
      b = nullptr;
    }
  }

 public:
  arr2d(int d1 = 0, int d2 = 0) : d1(d1), d2(d2), sz(d1 * d2) {
    allocate(sz);
    if (NeedFill<T>::value) {
      for (int i : range(sz)) {
        ::new ((void*)(b + i)) T;
      }
    }
  }
  arr2d(int d1, int d2, const T& init) : d1(d1), d2(d2), sz(d1 * d2) {
    allocate(sz);
    for (int i : range(sz)) {
      ::new ((void*)(b + i)) T(init);
    }
  }
  arr2d(T* b, int d1, int d2) : b(b), d1(d1), d2(d2), sz(d1 * d2) {}
  int size() const { return sz; }
  int dim1() const { return d1; }
  int dim2() const { return d2; }
  T* begin() { return b; }
  T* end() { return b + sz; }
  T& operator()(int i1, int i2) { return b[i1 * d2 + i2]; }
  const T& operator()(int i1, int i2) const { return b[i1 * d2 + i2]; }
  T& operator[](const pii& p) { return operator()(p.first, p.second); }
  const T& operator[](const pii& p) const {
    return operator()(p.first, p.second);
  }
  arr<T> operator[](int at) { return arr<T>(b + at * d2, d2); }
  vector<vector<T>> view() {
    vector<vector<T>> res(min(d1, 50));
    for (int i : range(res.size())) {
      res[i] = (*this)[i].view();
    }
    return res;
  }
};
inline bool isWhitespace(int c) { return isspace(c) || c == EOF; }
class Input {
 private:
  bool exhausted = false;
  int bufSize = 4096;
  char* buf = new char[bufSize];
  int bufRead = 0;
  int bufAt = 0;

 public:
  inline int get() {
    if (exhausted) {
      return EOF;
    }
    if (bufRead == bufAt) {
      bufRead = fread(buf, sizeof(char), bufSize, stdin);
      bufAt = 0;
    }
    if (bufRead == bufAt) {
      exhausted = true;
      return EOF;
    }
    return buf[bufAt++];
  }
  inline int peek() {
    if (exhausted) {
      return EOF;
    }
    if (bufRead == bufAt) {
      bufRead = fread(buf, sizeof(char), bufSize, stdin);
      bufAt = 0;
    }
    if (bufRead == bufAt) {
      exhausted = true;
      return EOF;
    }
    return buf[bufAt];
  }

 private:
  template <typename T>
  inline T readInteger() {
    int c = skipWhitespace();
    int sgn = 1;
    if (c == '-') {
      sgn = -1;
      c = get();
    }
    T res = 0;
    do {
      if (!isdigit(c)) {
        return sgn * res;
      }
      res *= 10;
      res += c - '0';
      c = get();
    } while (!isWhitespace(c));
    return res * sgn;
  }
  void initArrays(int) {}
  template <typename T, class... Vs>
  void initArrays(int n, arr<T>& array, Vs&... vs) {
    array = arr<T>(n);
    initArrays(n, vs...);
  }
  template <typename T, class... Vs>
  void initArrays(int n, vector<T>&, Vs&... vs) {
    initArrays(n, vs...);
  }
  void readImpl(int) {}
  template <typename T, class... Vs>
  void readImpl(int i, arr<T>& arr, Vs&... vs) {
    arr[i] = readType<T>();
    readImpl(i, vs...);
  }
  template <typename T, class... Vs>
  void readImpl(int i, vector<T>& arr, Vs&... vs) {
    arr.push_back(readType<T>());
    readImpl(i, vs...);
  }

 public:
  inline int skipWhitespace() {
    int c;
    while (isWhitespace(c = get()) && c != EOF)
      ;
    return c;
  }
  inline int peekNext() {
    while (isWhitespace(peek()) && peek() != EOF) {
      get();
    }
    return peek();
  }
  inline int readInt() { return readInteger<int>(); }
  inline ll readLong() { return readInteger<ll>(); }
  inline unsigned readUnsigned() { return readInteger<unsigned>(); }
  string readString() {
    int c = skipWhitespace();
    if (c == EOF) {
      return "";
    }
    string res;
    do {
      res.push_back(c);
    } while (!isWhitespace(c = get()));
    return res;
  }
  arr<int> readIntArray(int size) { return readArray<int>(size); }
  arr<ll> readLongArray(int size) { return readArray<ll>(size); }
  arr<double> readDoubleArray(int size) { return readArray<double>(size); }
  arr<string> readStringArray(int size) { return readArray<string>(size); }
  arr<char> readCharArray(int size) { return readArray<char>(size); }
  template <typename T>
  T readType() {
    throw "Operation not supported";
  }
  template <typename U, typename V>
  pair<U, V> readType() {
    U first = readType<U>();
    V second = readType<V>();
    return make_pair(first, second);
  }
  template <typename T>
  arr<T> readArray(int n) {
    arr<T> res(n, T());
    for (int i : range(n)) {
      res[i] = readType<T>();
    }
    return res;
  }
  template <class... Vs>
  void readArrays(int n, Vs&... vs) {
    initArrays(n, vs...);
    for (int i : range(n)) {
      readImpl(i, vs...);
    }
  }
  template <typename U, typename V>
  arr<pair<U, V>> readArray(int n) {
    arr<pair<U, V>> res(n);
    for (int i : range(n)) {
      res[i] = readType<U, V>();
    }
    return res;
  }
  template <typename T>
  arr2d<T> readTable(int rows, int cols) {
    arr2d<T> result(rows, cols);
    for (int i : range(rows)) {
      for (int j : range(cols)) {
        result(i, j) = readType<T>();
      }
    }
    return result;
  }
  arr2d<int> readIntTable(int rows, int cols) {
    return readTable<int>(rows, cols);
  }
  arr2d<char> readCharTable(int rows, int cols) {
    return readTable<char>(rows, cols);
  }
  string readLine() {
    int c = get();
    if (c == EOF) {
      return "";
    }
    string res;
    do {
      res.push_back(c);
      c = get();
    } while (c != '\n' && c != '\r' && c != EOF);
    return res;
  }
  inline double readDouble() {
    int c = skipWhitespace();
    int sgn = 1;
    if (c == '-') {
      sgn = -1;
      c = get();
    }
    double res = 0;
    do {
      if (tolower(c) == 'e') {
        return sgn * res * dPower(double(10), readInt());
      }
      if (!isdigit(c)) {
        return sgn * res;
      }
      res *= 10;
      res += c - '0';
      c = get();
    } while (!isWhitespace(c) && c != '.');
    if (c == '.') {
      double add = 0;
      int length = 0;
      c = get();
      do {
        if (tolower(c) == 'e') {
          return sgn * (res + add * dPower(double(10), -length)) *
                 dPower(double(10), readInt());
        }
        if (!isdigit(c)) {
          res += add * dPower(10, -length);
          return res * sgn;
        }
        add *= 10;
        add += c - '0';
        length++;
        c = get();
      } while (!isWhitespace(c));
      res += add * dPower(double(10), -length);
    }
    return res * sgn;
  }
  inline char readChar() {
    int c = skipWhitespace();
    if (c == EOF) {
      return 0;
    }
    return c;
  }
  inline bool isExhausted() { return exhausted; }
  inline void setBufSize(int newBufSize) {
    if (newBufSize > bufSize) {
      char* newBuf = new char[newBufSize];
      memcpy(newBuf, buf, bufSize);
      buf = newBuf;
    }
    bufSize = newBufSize;
  }
};
template <>
inline double Input::readType() {
  return readDouble();
}
template <>
inline int Input::readType() {
  return readInt();
}
template <>
inline ll Input::readType() {
  return readLong();
}
template <>
inline unsigned Input::readType() {
  return readUnsigned();
}
template <>
inline char Input::readType() {
  return readChar();
}
template <>
inline string Input::readType() {
  return readString();
}
Input in;
class Output {
 private:
  ostream* out;
  template <typename T>
  inline void printSingle(const T& value) {
    *out << value;
  }
  template <typename T>
  void printSingle(const vector<T>& array) {
    size_t n = array.size();
    for (int i : range(n)) {
      *out << array[i];
      if (i + 1 != n) {
        *out << ' ';
      }
    }
  }
  template <typename T>
  void printSingle(const arr<T>& array) {
    int n = array.size();
    for (int i : range(n)) {
      *out << array[i];
      if (i + 1 != n) {
        *out << ' ';
      }
    }
  }
  template <typename T>
  void printSingle(const arr2d<T>& array) {
    size_t n = array.dim1();
    size_t m = array.dim2();
    for (int i : range(n)) {
      for (int j : range(m)) {
        *out << array(i, j);
        if (j + 1 != m) {
          *out << ' ';
        }
      }
      if (i + 1 != n) {
        *out << '\n';
      }
    }
  }
  template <typename T, typename U>
  inline void printSingle(const pair<T, U>& value) {
    *out << value.first << ' ' << value.second;
  }

 public:
  bool autoflush;
  Output(ostream& out, bool autoflush) : out(&out), autoflush(autoflush) {
    setPrecision(20);
  }
  void setOut(ostream& nOut) {
    out = &nOut;
    setPrecision(20);
  }
  inline void print() {}
  template <typename T, typename... Targs>
  inline void print(const T& first, const Targs... args) {
    printSingle(first);
    if (sizeof...(args) != 0) {
      *out << ' ';
      print(args...);
    }
    if (autoflush) {
      flush();
    }
  }
  template <typename... Targs>
  inline void printLine(const Targs... args) {
    print(args...);
    *out << '\n';
    if (autoflush) {
      flush();
    }
  }
  inline void flush() { out->flush(); }
  inline void setPrecision(int digs) { *out << fixed << setprecision(digs); }
};
Output out(cout, false);
Output err(cerr, true);
template <class Edge>
class Graph {
 public:
  int vertexCount;
  int edgeCount = 0;

 private:
  vector<vector<Edge>> edges;

 public:
  Graph(int vertexCount)
      : vertexCount(vertexCount), edges(vertexCount, vector<Edge>()) {}
  template <typename... Ts>
  int addEdge(int from, int to, Ts... args) {
    edges[from].emplace_back(to, edgeCount, args...);
    int directId = edges[from].size() - 1;
    if (Edge::reversable) {
      edges[to].push_back(edges[from][directId].reverseEdge(from));
      int revId = edges[to].size() - 1;
      edges[from][directId].setReverseId(revId);
      edges[to][revId].setReverseId(directId);
    }
    edgeCount++;
    return directId;
  }
  vector<Edge>& operator[](int at) { return edges[at]; }
  void addVertices(int count) {
    vertexCount += count;
    edges.resize(vertexCount);
  }
  void clear() {
    edgeCount = 0;
    for (int i : range(vertexCount)) {
      edges[i].clear();
    }
  }
};
class BaseEdge {
 public:
  const static bool reversable = false;
  int to;
  int id;
  BaseEdge(int to, int id) : to(to), id(id) {}
  BaseEdge reverseEdge(int) { throw "Unsupported operation exception"; }
  void setReverseId(int) { throw "Unsupported operation exception"; }
};
template <typename W>
class WeightedEdge : public BaseEdge {
 public:
  const static bool reversable = false;
  W weight;
  WeightedEdge(int to, int id, W weight) : BaseEdge(to, id), weight(weight) {}
  WeightedEdge<W> reverseEdge(int) { throw "Unsupported operation exception"; }
  void setReverseId(int) { throw "Unsupported operation exception"; }
};
template <typename T>
class que : public queue<T> {
  using parent = queue<T>;

 public:
  que() : parent() {}
  que(const que<T>& q) : parent(q) {}
  que(que<T>&& q) noexcept : parent(move(q)) {}
  T pop() {
    T res = parent::front();
    parent::pop();
    return res;
  }
  que<T>& operator=(que<T>&& __x) noexcept {
    parent::operator=(__x);
    return *this;
  }
  que<T>& operator=(const que<T>& __x) {
    parent::operator=(__x);
    return *this;
  }
};
using qi = que<int>;
class EYegorVRespublikeDagestan {
 public:
  void solve() {
    int n = in.readInt();
    int m = in.readInt();
    arr<int> u, v, t;
    in.readArrays(m, u, v, t);
    decreaseByOne(u, v);
    Graph<WeightedEdge<int>> graph(n);
    for (int i : range(m)) {
      graph.addEdge(v[i], u[i], t[i]);
    }
    arr<int> color(n, -1);
    color[n - 1] = 0;
    int infty = numeric_limits<int>::max();
    arr<int> dist(n, infty);
    dist[n - 1] = 0;
    que<int> q;
    q.push(n - 1);
    while (!q.empty()) {
      int cur = q.pop();
      for (auto& e : graph[cur]) {
        if (dist[e.to] == infty && color[e.to] == e.weight) {
          dist[e.to] = dist[cur] + 1;
          q.push(e.to);
        } else if (color[e.to] != e.weight) {
          color[e.to] = 1 - e.weight;
        }
      }
    }
    for (int& i : color) {
      if (i == -1) {
        i = 0;
      }
    }
    out.printLine(dist[0] == infty ? -1 : dist[0]);
    for (int i : color) {
      out.print(i);
    }
    out.printLine();
  }
};
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  EYegorVRespublikeDagestan solver;
  solver.solve();
  fflush(stdout);
  return 0;
}
