#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, ans, ans1, ans2, ans3, ans4;
vector<int> e[5005];
queue<int> q;
int d[3005][3005];
int f[3005][3], g[3005][3];
void get(int x) {
  q.push(x);
  for (int i = 1; i <= n; i++) d[x][i] = 1000000000;
  d[x][x] = 0;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i = 0; i < e[t].size(); i++)
      if (d[x][e[t][i]] == 1000000000) {
        d[x][e[t][i]] = d[x][t] + 1;
        q.push(e[t][i]);
      }
  }
}
void pre(int x) {
  for (int i = 1; i <= n; i++) {
    int t = i;
    for (int j = 0; j < 3; j++) {
      int p = f[x][j];
      if (d[p][x] < d[t][x] && d[t][x] != 1000000000) swap(f[x][j], t);
    }
    t = i;
    for (int j = 0; j < 3; j++) {
      int p = g[x][j];
      if (d[x][p] < d[x][t] && d[x][t] != 1000000000) swap(g[x][j], t);
    }
  }
}
void solve(int u, int v) {
  if (d[u][v] == 1000000000) return;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      int p1 = f[u][i], p2 = g[v][j];
      if (p1 == 0 || p2 == 0) continue;
      if (p1 != p2 && p1 != v && p2 != u &&
          d[p1][u] + d[u][v] + d[v][p2] > ans) {
        ans = d[p1][u] + d[u][v] + d[v][p2];
        ans1 = p1, ans2 = u, ans3 = v, ans4 = p2;
      }
    }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int u, v;
    u = read();
    v = read();
    e[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) get(i);
  for (int i = 1; i <= n; i++) pre(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j) solve(i, j);
  cout << ans1 << ' ' << ans2 << ' ' << ans3 << ' ' << ans4 << endl;
  return 0;
}
