#include <bits/stdc++.h>
using namespace std;
long long int n, m, i, a, b, j, k, l, ans, tmp;
int arr[4010][4010] = {0};
vector<vector<int> > v(4010);
int len[4010] = {0};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  ans = INT_MAX;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    arr[a][b] = 1;
    arr[b][a] = 1;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (i = 1; i <= n; i++) len[i] = v[i].size();
  for (i = 1; i <= n; i++) {
    l = len[i];
    for (j = 0; j < l; j++) {
      for (k = j + 1; k < l; k++) {
        if (arr[v[i][j]][v[i][k]]) {
          tmp = len[i] + len[v[i][j]] + len[v[i][k]] - 6;
          if (tmp < ans) {
            ans = tmp;
          }
        }
      }
    }
  }
  if (ans != INT_MAX)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
