#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
int N, M;
int dist[3010][3010];
vector<int> adj[3010];
vector<pair<int, int>> to[3010];
vector<pair<int, int>> from[3010];
int vis[3010];
void bfs(int u) {
  for (int(i) = 0; (i) < (N); (i)++) vis[i] = 0;
  for (int(i) = 0; (i) < (N); (i)++) dist[u][i] = INF;
  dist[u][u] = 0;
  deque<int> q;
  q.push_back(u);
  while (int((q).size()) > 0) {
    int v = q.front();
    q.pop_front();
    if (vis[v]) continue;
    vis[v] = 1;
    for (int(i) = 0; (i) < (int((adj[v]).size())); (i)++) {
      int t = adj[v][i];
      if (dist[u][t] > dist[u][v] + 1) {
        dist[u][t] = dist[u][v] + 1;
        q.push_back(t);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout << fixed;
  cout.tie(0);
  cin.tie(0);
  cin >> N >> M;
  for (int(i) = 0; (i) < (M); (i)++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    sort(adj[i].begin(), adj[i].end());
    adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end());
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    bfs(i);
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    for (int(j) = 0; (j) < (N); (j)++) {
      if (dist[j][i] < INF) {
        to[i].push_back(make_pair(dist[j][i], j));
      }
      if (dist[i][j] < INF) {
        from[i].push_back(make_pair(dist[i][j], j));
      }
    }
    sort(to[i].begin(), to[i].end());
    sort(from[i].begin(), from[i].end());
  }
  vector<int> ans;
  int max = 0;
  for (int(i) = 0; (i) < (N); (i)++) {
    for (int(j) = 0; (j) < (N); (j)++) {
      if (i == j) continue;
      if (dist[i][j] >= INF) continue;
      int s1 = int((to[i]).size());
      int s2 = int((from[j]).size());
      set<int> vertices;
      for (int k1 = s1 - 3; k1 < s1; k1++) {
        if (k1 < 0) continue;
        for (int k2 = s2 - 3; k2 < s2; k2++) {
          if (k2 < 0) continue;
          int a = to[i][k1].second;
          int b = from[j][k2].second;
          int m = dist[a][i] + dist[i][j] + dist[j][b];
          if (m <= max) continue;
          vertices.clear();
          vertices.insert(i);
          vertices.insert(j);
          vertices.insert(a);
          vertices.insert(b);
          if (int((vertices).size()) == 4) {
            ans.clear();
            ans.push_back(a);
            ans.push_back(i);
            ans.push_back(j);
            ans.push_back(b);
            max = m;
          }
        }
      }
    }
  }
  for (int(i) = 0; (i) < (int((ans).size())); (i)++) {
    cout << ans[i] + 1 << " ";
  }
  cout << '\n';
}
