#include <bits/stdc++.h>
using namespace std;
vector<int> adj[5000];
int s, vis[5000] = {0};
priority_queue<int, vector<int>, greater<int>> q;
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    for (auto u : adj[i]) {
      for (auto v : adj[u]) {
        if (count(adj[v].begin(), adj[v].end(), i)) {
          s = adj[i].size() + adj[u].size() + adj[v].size();
          q.push(s - 6);
        }
      }
    }
  }
  if (q.size() == 0)
    cout << -1;
  else
    cout << q.top();
  return 0;
}
