#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int nm = 0, fh = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fh = -1;
  for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
  return nm * fh;
}
int n, m, cnt, hd, tl, dis[1000020], que[1000020];
bool vis[1000020];
vector<int> vec[1000020][10];
inline void link(int u, int v, int w) {
  int x = v;
  while (w > 9) vec[++cnt][w % 10].push_back(x), x = cnt, w /= 10;
  vec[u][w % 10].push_back(x);
}
int main() {
  n = read(), m = read(), cnt = n;
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    link(u, v, i), link(v, u, i);
  }
  que[hd = tl = 1] = 1, dis[1] = 0;
  while (hd <= tl) {
    int pos = hd;
    while (pos <= tl && dis[que[pos]] == dis[que[hd]]) pos++;
    pos--;
    for (int i = 0; i < 10; i++)
      for (int j = hd; j <= pos; j++) {
        int x = que[j];
        for (int k = 0, TP = vec[x][i].size(); k < TP; k++)
          if (!vis[vec[x][i][k]])
            vis[vec[x][i][k]] = true,
            dis[vec[x][i][k]] = (dis[x] * 10ll % 1000000007 + i) % 1000000007,
            que[++tl] = vec[x][i][k];
      }
    hd = pos + 1;
  }
  for (int i = 2; i <= n; i++) printf("%d\n", dis[i]);
  return 0;
}
