#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const long long mod = 1e9 + 7;
const int maxn = 3030;
const int inf = 1e9;
int n, m;
vector<int> g[maxn];
int dist[maxn][maxn];
int farthest[maxn][3], farthestr[maxn][3];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dist[i][j] = inf;
    }
    dist[i][i] = 0;
  }
  for (int x = 1; x <= n; x++) {
    queue<int> qq;
    qq.push(x);
    while (qq.size()) {
      int at = qq.front();
      qq.pop();
      for (int to : g[at]) {
        if (dist[x][to] == inf) {
          dist[x][to] = dist[x][at] + 1;
          qq.push(to);
        }
      }
    }
  }
  memset(farthest, -1, sizeof(farthest));
  memset(farthestr, -1, sizeof(farthestr));
  for (int at = 1; at <= n; at++) {
    for (int to = 1; to <= n; to++) {
      if (at == to) continue;
      if (dist[at][to] == inf) continue;
      int cur = to;
      for (int k = 0; k < 3; k++) {
        if (farthest[at][k] == -1 ||
            dist[at][farthest[at][k]] < dist[at][cur]) {
          swap(farthest[at][k], cur);
        }
      }
    }
    for (int to = 1; to <= n; to++) {
      if (at == to) continue;
      if (dist[at][to] == inf) continue;
      int cur = at;
      for (int k = 0; k < 3; k++) {
        if (farthestr[to][k] == -1 ||
            dist[farthestr[to][k]][to] < dist[cur][to]) {
          swap(farthestr[to][k], cur);
        }
      }
    }
  }
  vector<int> ans;
  int distans = -inf;
  for (int b = 1; b <= n; b++) {
    for (int c = 1; c <= n; c++) {
      if (b == c) continue;
      if (dist[b][c] == inf) continue;
      for (int aa = 0; aa < 3; aa++) {
        int a = farthestr[b][aa];
        if (a == -1) continue;
        if (a == c || a == b) continue;
        for (int dd = 0; dd < 3; dd++) {
          int d = farthest[c][dd];
          if (d == -1) continue;
          if (a == d) continue;
          if (d == b || d == c) continue;
          int walk = dist[a][b] + dist[b][c] + dist[c][d];
          if (walk > distans) {
            ans.clear();
            ans.push_back(a);
            ans.push_back(b);
            ans.push_back(c);
            ans.push_back(d);
            distans = walk;
          }
        }
      }
    }
  }
  cerr << distans << endl;
  assert(ans.size());
  for (int i : ans) cout << i << " ";
  cout << endl;
  return 0;
}
