/*#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef stack<long long> ss;
#define get(a) #a
//#define DEBUG
//#define local
#define endl '\n'
#ifdef DEBUG
#define debug(args...) {dbg,args; cerr<<endl;}
#else
#define debug(args...) // Just strip off all debug tokens
#endif
struct debugger
{
template<typename T> debugger& operator , (const T& v)
{
cerr<<v<<" ";
return *this;
}
} dbg;
#define INF 1000000000
int main(){
std::ios::sync_with_stdio(false);
#ifdef local
freopen("in.txt","r",stdin);
#endif
int n,m;
cin>>n>>m;
int min_sum = INF;
vector< vector<int> > arr;
vector< pair<int,int> > p;
for(int i = 0;i < n;i++){
vector<int> q(m,0);
arr.push_back(q);
}
int a,b,c;
for (int i = 0; i < m; ++i)
{
cin>>a>>b;
a--;
b--;
arr[a][b] = 1;
arr[b][a] = 1;
p.push_back(make_pair(a,b));
}
vector<vector<int> > v;
int sum[n];
for(int i = 0;i < n;i++){
int sums = 0;
vector<int> q;
//q.push_back(-1);
for(int j = 0;j < m;j++){
sums += arr[i][j];
if(arr[i][j])
q.push_back(j);
}
v.push_back(q);
sum[i] = sums;
}
arr.clear();
vector<int>::iterator it;
for(int i = 0;i < p.size();i++){
a = p[i].first;
b = p[i].second;
for(int j = i+1;j < p.size();j++){
if(p[j].first == a){
if(v[b].size() > 0){
it = lower_bound(v[b].begin(),v[b].end(),p[j].second);
if(*it == p[j].second){
//cout<<a<<" "<<b<<" "<<p[j].second<<endl;
min_sum = min(min_sum,sum[a] + sum[b] + sum[p[j].second] - 6);
}
}
}
if(p[j].second == a){
if(v[b].size() > 0){
it = lower_bound(v[b].begin(),v[b].end(),p[j].first);
if(*it == p[j].first){
//cout<<a<<" "<<b<<" "<<p[j].first<<" minsum = "<<min_sum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