#include <bits/stdc++.h>
using namespace std;
vector<int> p[3030];
long long dist[3030][3030];
pair<long long, long long> out[3030][5];
pair<long long, long long> in[3030][5];
void bfs(int x) {
  dist[x][x] = 0;
  queue<pair<long long, long long> > q;
  q.push(make_pair(0, x));
  pair<long long, long long> t;
  while (!q.empty()) {
    t = q.front();
    q.pop();
    for (int i = 0; i < p[t.second].size(); i++) {
      if (dist[x][p[t.second][i]] > 1 + t.first) {
        dist[x][p[t.second][i]] = 1 + t.first;
        out[x][0] = make_pair(dist[x][p[t.second][i]], p[t.second][i]);
        sort(out[x], out[x] + 5);
        in[p[t.second][i]][0] = make_pair(dist[x][p[t.second][i]], x);
        sort(in[p[t.second][i]], in[p[t.second][i]] + 5);
        q.push(make_pair(dist[x][p[t.second][i]], p[t.second][i]));
      }
    }
  }
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    p[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dist[i][j] = 1e18;
    }
    for (int j = 0; j <= 4; j++) {
      out[i][j] = make_pair(-1, -1);
      in[i][j] = make_pair(-1, -1);
    }
  }
  for (int i = 1; i <= n; i++) bfs(i);
  long long l1, l2;
  int res[5];
  long long maxx = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      l2 = dist[i][j];
      if (l2 == 1e18) continue;
      for (int k = 4; k >= 0; k--) {
        for (int k1 = 4; k1 >= 0; k1--) {
          l1 = l2;
          x = in[i][k].second;
          y = out[j][k1].second;
          if (x == y) continue;
          if (x == i || x == j) continue;
          if (y == i || y == j) continue;
          if (x == -1 || y == -1) continue;
          l1 += in[i][k].first;
          l1 += out[j][k1].first;
          if (maxx < l1) {
            maxx = l1;
            res[0] = x;
            res[1] = i;
            res[2] = j;
            res[3] = y;
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) printf("%d ", res[i]);
  return 0;
}
