#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[3005], gt[3005];
vector<pair<int, int> > fg[3005], fgt[3005];
int dist[3005][3005];
void bfs(const vector<int> *g, int s) {
  queue<int> q;
  int *d = dist[s];
  d[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (d[v] == -1) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    g[u].push_back(v);
    gt[v].push_back(u);
  }
  memset(dist, -1, sizeof(dist));
  for (int i = 0; i < n; i++) {
    bfs(gt, i);
    for (int k = 0; k < 3; k++) {
      int v = i;
      for (int j = 0; j < n; j++) {
        if (count(fgt[i].begin(), fgt[i].end(), make_pair(dist[i][j], j)) > 0)
          continue;
        if (dist[i][j] > dist[i][v]) v = j;
      }
      if (v == i) break;
      fgt[i].push_back(make_pair(dist[i][v], v));
    }
  }
  memset(dist, -1, sizeof(dist));
  for (int i = 0; i < n; i++) {
    bfs(g, i);
    for (int k = 0; k < 3; k++) {
      int v = i;
      for (int j = 0; j < n; j++) {
        if (count(fg[i].begin(), fg[i].end(), make_pair(dist[i][j], j)) > 0)
          continue;
        if (dist[i][j] > dist[i][v]) v = j;
      }
      if (v == i) break;
      fg[i].push_back(make_pair(dist[i][v], v));
    }
  }
  int aa, bb, cc, dd, best = -1;
  for (int b = 0; b < n; b++) {
    for (int c = 0; c < n; c++) {
      if (c == b || dist[b][c] < 0) continue;
      for (int i = 0; i < fgt[b].size(); i++) {
        int a = fgt[b][i].second;
        if (a == b || a == c) continue;
        for (int j = 0; j < fg[c].size(); j++) {
          int d = fg[c][j].second;
          if (d == a || d == b || d == c) continue;
          int x = dist[b][c] + fgt[b][i].first + fg[c][j].first;
          if (x > best) {
            aa = a, bb = b, cc = c, dd = d;
            best = x;
          }
        }
      }
    }
  }
  printf("%d %d %d %d\n", aa + 1, bb + 1, cc + 1, dd + 1);
}
