#include <bits/stdc++.h>
using namespace std;
long long n, m, res, x, y;
bool vis[200200];
vector<long long> temp;
vector<vector<long long> > g;
void dfs(long long u) {
  vis[u] = 1;
  temp.push_back(u);
  for (long long i = 0; i < g[u].size(); i++)
    if (!vis[g[u][i]]) dfs(g[u][i]);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  g.clear();
  g.resize(n + 1);
  while (m--) {
    cin >> x >> y;
    g[y].push_back(x);
    g[x].push_back(y);
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      temp.clear();
      dfs(i);
      bool ok = 1;
      for (long long j = 0; j < temp.size(); j++)
        if (g[temp[j]].size() != 2) ok = 0;
      if (ok) res++;
    }
  }
  cout << res << endl;
  return 0;
}
