#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 8;
const long long MOD = 1e9 + 7;
const long long sz = 3e3 + 5;
void f_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
}
long long n, m;
set<long long> graph[sz];
set<long long> rev[sz];
long long dis[2][sz][sz];
bool vis[sz];
void bfs(long long node, set<long long> *g, long long type) {
  dis[type][node][node] = 0;
  queue<long long> q;
  q.push(node);
  vis[node] = true;
  while (!q.empty()) {
    auto el = q.front();
    q.pop();
    for (auto k : g[el]) {
      if (!vis[k]) {
        dis[type][node][k] = dis[type][node][el] + 1;
        vis[k] = true;
        q.push(k);
      }
    }
  }
}
int32_t main() {
  f_io();
  long long tc = 1;
  while (tc--) {
    cin >> n >> m;
    for (long long i = 1; i < m + 1; i++) {
      long long u, v;
      cin >> u >> v;
      graph[u].insert(v);
      rev[v].insert(u);
    }
    memset(dis, -1, sizeof dis);
    for (long long i = 1; i < n + 1; i++) {
      memset(vis, 0, sizeof vis);
      bfs(i, graph, 0);
    }
    for (long long i = 1; i < n + 1; i++) {
      memset(vis, 0, sizeof vis);
      bfs(i, rev, 1);
    }
    map<long long, vector<pair<long long, long long>>> forv;
    map<long long, vector<pair<long long, long long>>> back;
    for (long long i = 1; i < n + 1; i++) {
      vector<pair<long long, long long>> temp;
      for (long long j = 1; j < n + 1; j++) {
        temp.emplace_back(dis[0][i][j], j);
      }
      sort(begin(temp), end(temp));
      long long _t = 3;
      while (_t--) {
        forv[i].push_back(temp.back());
        temp.pop_back();
      }
    }
    for (long long i = 1; i < n + 1; i++) {
      vector<pair<long long, long long>> temp;
      for (long long j = 1; j < n + 1; j++) {
        temp.emplace_back(dis[1][i][j], j);
      }
      sort(begin(temp), end(temp));
      long long _t = 3;
      while (_t--) {
        back[i].push_back(temp.back());
        temp.pop_back();
      }
    }
    long long ans = INT_MIN, A, B, C, D;
    for (long long a = 1; a < n + 1; a++) {
      for (long long b = 1; b < n + 1; b++) {
        if (a == b || dis[0][a][b] == -1) continue;
        for (long long i = 0; i < 3; i++) {
          for (long long j = 0; j < 3; j++) {
            long long temp = dis[0][a][b];
            auto c = back[a][i], d = forv[b][j];
            if (a == c.second || a == d.second || b == c.second ||
                b == d.second || c.second == d.second)
              continue;
            temp += (c.first + d.first);
            if (temp > ans) {
              A = c.second, B = a, C = b, D = d.second;
              ans = temp;
            }
          }
        }
      }
    }
    cout << A << " " << B << " " << C << " " << D << "\n";
  }
}
