#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, a[4005], b[4005], p = 4001;
bool c[4005][4005];
map<int, int> mr;
vector<int> v[4005];
int main() {
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    ++mr[a[i]];
    ++mr[b[i]];
    c[a[i]][b[i]] = c[b[i]][a[i]] = 1;
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < v[a[i]].size(); j++) {
      if (v[a[i]][j] != b[i] && c[b[i]][v[a[i]][j]]) {
        p = min(p, mr[a[i]] + mr[b[i]] + mr[v[a[i]][j]] - 6);
      }
    }
  }
  if (p == 4001) {
    p = -1;
  }
  cout << p;
}
