#include <bits/stdc++.h>
using namespace std;
const int MAX = 5 << 10;
vector<int> G[MAX];
int n, m;
int E[MAX][2];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (m); i++) {
    scanf("%d %d", &E[i][0], &E[i][1]);
    G[E[i][0]].push_back(E[i][1]);
    G[E[i][1]].push_back(E[i][0]);
  }
  for (int i = (1); i <= (n); i++) sort(G[i].begin(), G[i].end());
  int ans = INT_MAX;
  for (int i = 0; i < (m); i++) {
    int a = E[i][0], b = E[i][1];
    int sum = ((int)G[a].size()) + ((int)G[b].size());
    for (int v : G[a])
      if (binary_search(G[b].begin(), G[b].end(), v)) {
        ans = min(ans, sum + ((int)G[v].size()) - 6);
      }
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans << endl;
  return 0;
}
