#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const double eps = 1e-6;
const int maxn = 3e3 + 10;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
vector<int> mp[maxn];
vector<pair<int, int> > a[maxn], b[maxn];
int n, m;
int dis[maxn][maxn];
int vis[maxn];
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
void SPFA(int st) {
  memset(vis, 0, sizeof(vis));
  queue<int> q;
  q.push(st);
  vis[st] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int v = 0; v < mp[u].size(); v++) {
      int next = mp[u][v];
      if (dis[st][next] > dis[st][u] + 1) {
        dis[st][next] = dis[st][u] + 1;
        if (!vis[next]) {
          vis[next] = 1;
          q.push(next);
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    mp[i].clear();
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j)
        dis[i][j] = 0;
      else
        dis[i][j] = inf;
    }
  }
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) SPFA(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (dis[i][j] != inf) a[i].push_back(make_pair(dis[i][j], j));
      if (dis[j][i] != inf) b[i].push_back(make_pair(dis[j][i], j));
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(a[i].begin(), a[i].end(), cmp);
    sort(b[i].begin(), b[i].end(), cmp);
  }
  int maxi = -1;
  int ans1, ans2, ans3, ans4;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || dis[i][j] == inf) continue;
      for (int k = 0; k < 4 && k < b[i].size(); k++) {
        int lf = b[i][k].second;
        if (lf == i || lf == j) continue;
        for (int l = 0; l < 4 && l < a[j].size(); l++) {
          int rt = a[j][l].second;
          if (rt == i || rt == j || rt == lf) continue;
          if (maxi < dis[lf][i] + dis[i][j] + dis[j][rt]) {
            maxi = dis[lf][i] + dis[i][j] + dis[j][rt];
            ans1 = lf;
            ans2 = i;
            ans3 = j;
            ans4 = rt;
          }
        }
      }
    }
  }
  printf("%d %d %d %d\n", ans1, ans2, ans3, ans4);
  return 0;
}
