#include <bits/stdc++.h>
using namespace std;
int N, M, min_dist[3005][3005];
pair<int, int> val[3005], pos[3005], val2[3005], pos2[3005];
vector<int> g[3005];
bool vis[3005];
void bfs(int st, int dist[]) {
  queue<int> q;
  q.push(st);
  dist[st] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
}
bool check(int a, int b, int c, int d) {
  int cnt = 0;
  if (!vis[a]) vis[a] = true, cnt++;
  if (!vis[b]) vis[b] = true, cnt++;
  if (!vis[c]) vis[c] = true, cnt++;
  if (!vis[d]) vis[d] = true, cnt++;
  vis[a] = vis[b] = vis[c] = vis[d] = false;
  return cnt == 4;
}
int main() {
  int u, v;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  memset(min_dist, 0x3f, sizeof min_dist);
  for (int i = 1; i <= N; i++) bfs(i, min_dist[i]);
  for (int i = 1; i <= N; i++) {
    val2[i] = val[i] = pair<int, int>(-0x7fffffff, -0x7fffffff);
    pos2[i] = pos[i] = pair<int, int>(-1, -1);
    for (int j = 1; j <= N; j++) {
      if (min_dist[i][j] != 0x3f3f3f3f && val[i].first < min_dist[i][j]) {
        val[i].first = min_dist[i][j];
        pos[i].first = j;
      }
      if (min_dist[j][i] != 0x3f3f3f3f && val2[i].first < min_dist[j][i]) {
        val2[i].first = min_dist[j][i];
        pos2[i].first = j;
      }
    }
    for (int j = 1; j <= N; j++) {
      if (min_dist[i][j] != 0x3f3f3f3f &&
          (min_dist[i][j] < val[i].first ||
           (min_dist[i][j] == val[i].first && j != pos[i].first)) &&
          val[i].second < min_dist[i][j]) {
        val[i].second = min_dist[i][j];
        pos[i].second = j;
      }
      if (min_dist[j][i] != 0x3f3f3f3f &&
          (min_dist[j][i] < val2[i].first ||
           (min_dist[j][i] == val2[i].first && j != pos2[i].first)) &&
          val2[i].second < min_dist[j][i]) {
        val2[i].second = min_dist[j][i];
        pos2[i].second = j;
      }
    }
  }
  int max_sum = -1;
  vector<int> ans;
  ans.resize(4);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      if (i != j && min_dist[i][j] != 0x3f3f3f3f) {
        if (check(pos2[i].first, i, j, pos[j].first)) {
          if (val2[i].first + min_dist[i][j] + val[j].first > max_sum) {
            max_sum = val2[i].first + min_dist[i][j] + val[j].first;
            ans[0] = pos2[i].first;
            ans[1] = i;
            ans[2] = j;
            ans[3] = pos[j].first;
          }
        }
        if (check(pos2[i].second, i, j, pos[j].first)) {
          if (val2[i].second + min_dist[i][j] + val[j].first > max_sum) {
            max_sum = val2[i].second + min_dist[i][j] + val[j].first;
            ans[0] = pos2[i].second;
            ans[1] = i;
            ans[2] = j;
            ans[3] = pos[j].first;
          }
        }
        if (check(pos2[i].first, i, j, pos[j].second)) {
          if (val2[i].first + min_dist[i][j] + val[j].second > max_sum) {
            max_sum = val2[i].first + min_dist[i][j] + val[j].second;
            ans[0] = pos2[i].first;
            ans[1] = i;
            ans[2] = j;
            ans[3] = pos[j].second;
          }
        }
        if (check(pos2[i].second, i, j, pos[j].second)) {
          if (val2[i].second + min_dist[i][j] + val[j].second > max_sum) {
            max_sum = val2[i].second + min_dist[i][j] + val[j].second;
            ans[0] = pos2[i].second;
            ans[1] = i;
            ans[2] = j;
            ans[3] = pos[j].second;
          }
        }
      }
    }
  for (int i = 0; i < 4; i++) printf("%d%c", ans[i], i == 3 ? '\n' : ' ');
  return 0;
}
