#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7ll;
const int N = (int)2e5 + 7;
vector<int> adj[N];
int visit[N];
map<int, int> mp;
int flag = 1, cntn = 0;
void dfs(int nd) {
  if (mp[nd] != 2) flag = 0;
  visit[nd] = 1;
  cntn++;
  for (int it : adj[nd]) {
    if (!visit[it]) dfs(it);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m))) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
    mp[a]++;
    mp[b]++;
  }
  int ans = 0;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    if (!visit[i]) {
      dfs(i);
      if (cntn > 2) ans += flag;
      flag = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
