/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
4 5
1 2
1 3
3 2
2 4
3 4
---+/
/+---test
6 3
2 3
4 5
5 6
---+/
/+---test
5 8
5 3
2 3
2 4
5 2
5 1
1 4
4 3
1 3
---+/

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  auto paths = new long[][](N);
  foreach (i; 0..M) {
    long x, y;
    readf(" %d %d ", &x, &y);
    --x; --y;
    paths[x] ~= y;
  }

  auto dp = new long[](N);
  dp[] = -1;

  long f(size_t v) {
    if (dp[v] != -1) return dp[v];
    dp[v] = 0;
    foreach (p; paths[v]) {
      dp[v].amax(f(p)+1);
    }
    return dp[v];
  }

  iota(N).each!f;
  dp.writeln;
  dp.maxE.writeln;
}
