#include <bits/stdc++.h>
using namespace std;
struct Node {
  int id;
  int val;
  Node() {}
  Node(int a = 0, int b = 0) {
    id = a;
    val = b;
  }
};
vector<Node> dist[3005], dist1[3005];
vector<int> g[3005];
int vis[3005];
int dis[3005];
int n, m;
void input() {
  for (int i = 1; i <= n; i++) {
    dist[i].clear();
    dist1[i].clear();
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
  }
}
void spfa(int s) {
  for (int i = 1; i <= n; i++) {
    dis[i] = INT_MAX;
  }
  queue<int> que;
  dis[s] = 0;
  memset(vis, 0, sizeof vis);
  que.push(s);
  vis[s] = 1;
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    vis[u] = 0;
    for (int i = 0; i < (int)g[u].size(); i++) {
      int v = g[u][i];
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        if (!vis[v]) {
          vis[v] = 1;
          que.push(v);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] != INT_MAX) {
      dist[s].push_back(Node(i, dis[i]));
      dist1[i].push_back(Node(s, dis[i]));
    }
  }
}
bool cmp(const Node &a, const Node &b) { return a.val > b.val; }
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    input();
    for (int i = 1; i <= n; i++) {
      spfa(i);
    }
    for (int i = 1; i <= n; i++) {
      sort(dist[i].begin(), dist[i].end(), cmp);
      sort(dist1[i].begin(), dist1[i].end(), cmp);
    }
    int start = -1;
    int second = -1;
    int third = -1;
    int forth = -1;
    int ans = -1;
    int sum = -1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < dist[i].size(); j++) {
        int tmp = 0;
        if (dist[i][j].val == INT_MAX || i == dist[i][j].id) continue;
        tmp += dist[i][j].val;
        for (int k = 0; k < min(3, (int)dist1[i].size()); k++) {
          for (int p = 0; p < min(3, (int)dist[dist[i][j].id].size()); p++) {
            if (dist1[i][k].val != INT_MAX &&
                dist[dist[i][j].id][p].val != INT_MAX) {
              if (dist1[i][k].id != dist[i][j].id && dist1[i][k].id != i &&
                  dist1[i][k].id != dist[dist[i][j].id][p].id) {
                if (dist[dist[i][j].id][p].id != i &&
                    dist[dist[i][j].id][p].id != dist[i][j].id &&
                    dist1[i][k].id != dist[dist[i][j].id][p].id) {
                  if ((tmp + dist1[i][k].val + dist[dist[i][j].id][p].val) >
                      sum) {
                    start = dist1[i][k].id;
                    second = i;
                    third = dist[i][j].id;
                    forth = dist[dist[i][j].id][p].id;
                    sum = (tmp + dist1[i][k].val + dist[dist[i][j].id][p].val);
                  }
                }
              }
            }
          }
        }
      }
    }
    cout << start << " " << second << " " << third << " " << forth << endl;
  }
  return 0;
}
