#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, d, disti, maxi, x, y;
vector<vector<int> > g;
int dist[3005][3005];
pair<int, int> ans[5000][4][3];
bool used[5000];
queue<pair<int, int> > cur;
map<int, bool> w;
int ansi[5];
void filled(int start) {
  for (int i = 1; i <= n; i++) {
    dist[start][i] = 1000000007;
    used[i] = 0;
  }
}
void bfs(int start) {
  cur.push(make_pair(start, 0));
  int x, y, to;
  while (cur.size()) {
    x = cur.front().first;
    y = cur.front().second;
    cur.pop();
    for (int i = 0; i < g[x].size(); i++) {
      to = g[x][i];
      if (used[to]) continue;
      used[to] = true;
      cur.push(make_pair(to, y + 1));
      dist[start][to] = y + 1;
    }
  }
}
void pythagorean(int start) {
  for (int i = 1; i <= n; i++) {
    if (dist[start][i] == 1000000007) dist[start][i] = -1000000007 / 4;
    if (i == start) continue;
    if (dist[start][i] > ans[start][1][1].second) {
      ans[start][1][1].second = dist[start][i];
      ans[start][1][1].first = i;
      if (ans[start][1][1].second > ans[start][2][1].second) {
        swap(ans[start][1][1], ans[start][2][1]);
        if (ans[start][2][1].second > ans[start][3][1].second) {
          swap(ans[start][2][1], ans[start][3][1]);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dist[i][start] == 1000000007) dist[i][start] = -1000000007 / 4;
    if (i == start) continue;
    if (dist[i][start] > ans[start][1][2].second) {
      ans[start][1][2].second = dist[i][start];
      ans[start][1][2].first = i;
      if (ans[start][1][2].second > ans[start][2][2].second) {
        swap(ans[start][1][2], ans[start][2][2]);
        if (ans[start][2][2].second > ans[start][3][2].second) {
          swap(ans[start][2][2], ans[start][3][2]);
        }
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  ;
  scanf("%d", &m);
  ;
  g.resize(n + 5);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    ;
    scanf("%d", &y);
    ;
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    filled(i);
    bfs(i);
  }
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= n + 1; j++)
      if (dist[i][j] == 0) dist[i][j] = -1000000007 / 4;
  for (int i = 1; i <= n; i++) {
    pythagorean(i);
  }
  for (int b = 1; b <= n; b++) {
    for (int c = 1; c <= n; c++) {
      if (b == c) continue;
      w[b] = 1;
      w[c] = 1;
      for (int i = 3; i >= 1; i--) {
        if (ans[b][i][2].first == 0) break;
        if (w[ans[b][i][2].first] != 1) {
          w[ans[b][i][2].first]++;
          a = ans[b][i][2].first;
          for (int j = 3; j >= 1; j--) {
            if (ans[c][j][1].first == 0) break;
            if (w[ans[c][j][1].first] != 1) {
              d = ans[c][j][1].first;
              disti = dist[a][b] + dist[b][c] + dist[c][d];
              if (disti > maxi) {
                maxi = disti;
                ansi[1] = a;
                ansi[2] = b;
                ansi[3] = c;
                ansi[4] = d;
              }
            }
          }
          w[a] = 0;
        }
      }
      w[b] = 0;
      w[c] = 0;
    }
  }
  cout << ansi[1] << " " << ansi[2] << " " << ansi[3] << " " << ansi[4] << endl;
  return 0;
}
