#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<vector<long long> > g;
vector<bool> used;
vector<long long> comp;
void dfs(long long v) {
  used[v] = true;
  for (long long i = 0; i < g[v].size(); i++)
    if (!used[g[v][i]]) dfs(g[v][i]);
  comp.push_back(v);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  used.assign(n, false);
  g = vector<vector<long long> >(n);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (!used[i]) {
      comp.clear();
      dfs(i);
      if (comp.size() <= 2) continue;
      bool ok = true;
      for (long long j = 0; j < comp.size(); j++)
        if (g[comp[j]].size() != 2) ok = false;
      if (ok) ans++;
    }
  }
  cout << ans;
  return 0;
}
