#include <bits/stdc++.h>
using namespace std;
void errDebug() {}
template <typename T, typename... Args>
void errDebug(T a, Args... args) {
  cerr << a << ' ';
  errDebug(args...);
}
const int N = 3010;
struct Edge {
  int from;
  int to;
  int weight;
  Edge(int f, int t, int w) : from(f), to(t), weight(w) {}
};
vector<Edge> edges;
vector<int> G[N];
int p[N];
int d[N];
bool in_queue[N];
int cnt[N];
int n;
int m;
void addEdge(int u, int v, int w) {
  int index = edges.size();
  edges.push_back(Edge(u, v, w));
  G[u].push_back(index);
}
bool SPFA(int s) {
  int u;
  queue<int> Q;
  memset(in_queue, 0, sizeof(in_queue));
  memset(cnt, 0, sizeof(cnt));
  memset(d, 0x3f, sizeof(d));
  d[s] = 0;
  in_queue[s] = true;
  Q.push(s);
  while (!Q.empty()) {
    in_queue[u = Q.front()] = false;
    Q.pop();
    for (int i = 0; i < G[u].size(); ++i) {
      Edge &e = edges[G[u][i]];
      if (d[e.to] > d[u] + e.weight) {
        d[e.to] = d[u] + e.weight;
        p[e.to] = G[u][i];
        if (!in_queue[e.to]) {
          Q.push(e.to);
          in_queue[e.to] = true;
          if (++cnt[e.to] > n) return false;
        }
      }
    }
  }
  return true;
}
int dist[3010][3010];
vector<pair<int, int>> aa[3010];
vector<pair<int, int>> bb[3010];
void solve() {
  for (int(i) = (0); (i) < (n); ++(i)) {
    SPFA(i);
    for (int(j) = (0); (j) < (n); ++(j)) dist[i][j] = d[j];
  }
  for (int(i) = (0); (i) < (n); ++(i)) {
    for (int(j) = (0); (j) < (n); ++(j)) {
      if (i == j) continue;
      if (dist[i][j] != 0x3f3f3f3f) {
        aa[i].push_back(make_pair(dist[i][j], j));
        bb[j].push_back(make_pair(dist[i][j], i));
      }
    }
  }
  for (int(i) = (0); (i) < (n); ++(i)) {
    sort(aa[i].begin(), aa[i].end(), greater<pair<int, int>>());
    sort(bb[i].begin(), bb[i].end(), greater<pair<int, int>>());
  }
  int res = -1;
  vector<int> list;
  for (int(i) = (0); (i) < (n); ++(i))
    for (int(j) = (0); (j) < (n); ++(j)) {
      if (i == j) continue;
      if (dist[i][j] == 0x3f3f3f3f) continue;
      int curr = dist[i][j];
      for (int(p) = (0); (p) < (min((int)bb[i].size(), 3)); ++(p))
        for (int(q) = (0); (q) < (min((int)aa[j].size(), 3)); ++(q)) {
          int u = bb[i][p].second;
          int v = aa[j][q].second;
          if (u == i || u == j) continue;
          if (v == i || v == j) continue;
          if (u == v) continue;
          if (curr + bb[i][p].first + aa[j][q].first > res) {
            res = curr + bb[i][p].first + aa[j][q].first;
            list = vector<int>({u, i, j, v});
          }
        }
    }
  for (int(i) = (0); (i) < (list.size()); ++(i)) cout << list[i] + 1 << " ";
  cout << endl;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(false);
  cin >> n >> m;
  for (int(i) = (0); (i) < (m); ++(i)) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    addEdge(x, y, 1);
  }
  solve();
  return 0;
}
