#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a[4009][4009], sm, sm1, sm2, mn = 1000000009;
vector<int> v[4009];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    v[x].push_back(y), v[y].push_back(x);
    a[x][y] = 1, a[y][x] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (v[i].size() < 2) continue;
    sm = v[i].size() - 2;
    for (int j = i + 1; j <= n; j++) {
      sm1 = sm;
      if (a[i][j] == 0 || v[j].size() < 2) continue;
      sm1 += v[j].size() - 2;
      for (int k = 0; k < v[j].size(); k++) {
        sm2 = sm1;
        if (v[j][k] == i || a[i][v[j][k]] == 0 || v[v[j][k]].size() < 2)
          continue;
        sm2 += v[v[j][k]].size() - 2;
        mn = min(mn, sm2);
      }
    }
  }
  if (mn == 1000000009) return cout << -1, 0;
  cout << mn;
  return 0;
}
