#include <bits/stdc++.h>
using namespace std;
vector<int> a[3001];
vector<pair<int, int> > from[3001];
vector<pair<int, int> > to[3001];
int d[3001][3001];
bool v[3001];
int n, m;
int main() {
  memset(d, -1, sizeof(d));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int s, t;
    scanf("%d %d", &s, &t);
    a[s].push_back(t);
  }
  for (int i = 1; i <= n; i++) {
    memset(v, 0, sizeof(v));
    queue<pair<int, int> > q;
    q.push(pair<int, int>(i, 0));
    v[i] = true;
    while (!q.empty()) {
      pair<int, int> c = q.front();
      int cur = c.first, x = c.second;
      q.pop();
      for (int j = 0; j < a[cur].size(); j++) {
        int p = a[cur][j];
        if (!v[p]) {
          v[p] = true, d[i][p] = x + 1, q.push(pair<int, int>(p, x + 1));
          from[i].push_back(pair<int, int>(x + 1, p));
          to[p].push_back(pair<int, int>(x + 1, i));
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(from[i].begin(), from[i].end());
    sort(to[i].begin(), to[i].end());
  }
  int maxd = 0;
  int ans[4];
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (d[i][j] != -1) {
        for (int q = 1; q <= 3; q++) {
          for (int r = 1; r <= 3; r++) {
            if ((int)to[i].size() - q < 0 || (int)from[j].size() - r < 0)
              continue;
            int x[4];
            int dist = to[i][to[i].size() - q].first + d[i][j] +
                       from[j][from[j].size() - r].first;
            x[0] = to[i][to[i].size() - q].second;
            x[1] = i, x[2] = j;
            x[3] = from[j][from[j].size() - r].second;
            bool no = false;
            for (int s = 0; s < 4; s++) {
              for (int t = s + 1; t < 4; t++)
                if (x[s] == x[t]) {
                  no = true;
                  break;
                }
              if (no) break;
            }
            if (!no && dist > maxd) {
              maxd = dist;
              memcpy(ans, x, sizeof(x));
            }
          }
        }
      }
      if (d[j][i] != -1) {
        for (int q = 1; q <= 3; q++) {
          for (int r = 1; r <= 3; r++) {
            if ((int)to[j].size() - q < 0 || (int)from[i].size() - r < 0)
              continue;
            int x[4];
            int dist = to[j][to[j].size() - q].first + d[j][i] +
                       from[i][from[i].size() - r].first;
            x[0] = to[j][to[j].size() - q].second;
            x[1] = j, x[2] = i;
            x[3] = from[i][from[i].size() - r].second;
            bool no = false;
            for (int s = 0; s < 4; s++) {
              for (int t = s + 1; t < 4; t++)
                if (x[s] == x[t]) {
                  no = true;
                  break;
                }
              if (no) break;
            }
            if (!no && dist > maxd) {
              maxd = dist;
              memcpy(ans, x, sizeof(x));
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) printf("%d%c", ans[i], " \n"[i == 3]);
  return 0;
}
