#include <bits/stdc++.h>
using namespace std;
int fr[3005][3], to[3005][3];
vector<int> vec[3005];
int dist[3005][3005], n, ed;
void bfs(int ds) {
  queue<int> q;
  q.push(ds);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i = 0; i < vec[t].size(); i++) {
      int m = vec[t][i];
      if (dist[ds][m] == 0 && m != ds) {
        dist[ds][m] = dist[ds][t] + 1;
        q.push(m);
        for (int is = 0; is < 3; is++) {
          if (dist[ds][m] > dist[ds][fr[ds][is]]) {
            for (int j = 1; j >= is; j--) fr[ds][j + 1] = fr[ds][j];
            fr[ds][is] = m;
            break;
          }
        }
        for (int is = 0; is < 3; is++) {
          if (dist[ds][m] > dist[to[m][is]][m]) {
            for (int j = 1; j >= is; j--) to[m][j + 1] = to[m][j];
            to[m][is] = ds;
            break;
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &ed);
  for (int i = 1; i <= ed; i++) {
    int as, bs;
    scanf("%d%d", &as, &bs);
    vec[as].push_back(bs);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  int mx1 = 0, mx2 = 0, mx3 = 0, mx4 = 0, mxans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == i || dist[i][j] == 0) continue;
      int mx = 0, sta = 0, stb = 0;
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          int sa = to[i][k], sb = fr[j][l];
          if (sa == j || sa == sb || sb == i || sa == 0 || sb == 0) continue;
          if (mx < dist[sa][i] + dist[j][sb]) {
            mx = dist[sa][i] + dist[j][sb];
            sta = sa;
            stb = sb;
          }
        }
      }
      mx += dist[i][j];
      if (sta == 0 && stb == 0) continue;
      if (mx > mxans) {
        mxans = mx;
        mx1 = sta;
        mx2 = i;
        mx3 = j;
        mx4 = stb;
      }
    }
  }
  printf("%d %d %d %d\n", mx1, mx2, mx3, mx4);
  return 0;
}
