#include <bits/stdc++.h>
using namespace std;
int const lim = 3000 + 10;
int shortest[lim][lim];
bool vis[lim];
vector<int> adj[lim + 10];
int dp1[4005][5];
int dp2[4005][5];
int n;
void BFS() {
  for (int nod = 1; nod <= n; nod++) {
    queue<int> q;
    memset(vis, 0, sizeof vis);
    q.push(nod);
    shortest[nod][nod] = 0;
    vis[nod] = true;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int i = 0; i < adj[v].size(); i++) {
        int che = adj[v][i];
        if (vis[che]) continue;
        shortest[nod][che] = shortest[nod][v] + 1;
        vis[che] = true;
        q.push(che);
      }
    }
  }
}
int main() {
  memset(shortest, -1, sizeof shortest);
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, edge;
    cin >> x >> edge;
    adj[x].push_back(edge);
  }
  BFS();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (shortest[i][j] > shortest[i][dp1[i][0]])
        dp1[i][2] = dp1[i][1], dp1[i][1] = dp1[i][0], dp1[i][0] = j;
      else if (shortest[i][j] > shortest[i][dp1[i][1]])
        dp1[i][2] = dp1[i][1], dp1[i][1] = j;
      else if (shortest[i][j] > shortest[i][dp1[i][2]])
        dp1[i][2] = j;
      if (shortest[i][j] > shortest[dp2[j][0]][j])
        dp2[j][2] = dp2[j][1], dp2[j][1] = dp2[j][0], dp2[j][0] = i;
      else if (shortest[i][j] > shortest[dp2[j][1]][j])
        dp2[j][2] = dp2[j][1], dp2[j][1] = i;
      else if (shortest[i][j] > shortest[dp2[j][2]][j])
        dp2[j][2] = i;
    }
  }
  int ans1, ans2, ans3, ans4;
  long long ans = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int b = i, c = j;
      if (i == j || shortest[b][c] == -1) continue;
      for (int l = 0; l < 3; l++) {
        for (int k = 0; k < 3; k++) {
          int a = dp2[b][l], d = dp1[c][k];
          if ((a == d || a == b || a == c || d == b || d == c) ||
              (shortest[a][b] == -1 || shortest[c][d] == -1))
            continue;
          if (shortest[a][b] + shortest[b][c] + shortest[c][d] > ans)
            ans = shortest[a][b] + shortest[b][c] + shortest[c][d], ans1 = a,
            ans2 = b, ans3 = c, ans4 = d;
        }
      }
    }
  }
  cout << ans1 << " " << ans2 << " " << ans3 << " " << ans4 << endl;
}
