#include <bits/stdc++.h>
using namespace std;
const int64_t nax = 2e5 + 100;
int64_t deg[nax];
vector<vector<int64_t>> adj;
vector<bool> vis;
vector<int64_t> comp;
void dfs(int64_t s) {
  if (vis[s]) return;
  vis[s] = 1;
  comp.push_back(s);
  for (auto& x : adj[s]) {
    if (!vis[x]) dfs(x);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t n, m;
  cin >> n >> m;
  adj.resize(n);
  vis.resize(n, false);
  for (int64_t i = 0; i < m; ++i) {
    int64_t x, y;
    cin >> x >> y;
    --x, --y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    deg[x]++, deg[y]++;
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < n; ++i) {
    if (!vis[i]) {
      dfs(i);
      bool ok = 1;
      for (auto& x : comp) ok &= deg[x] == 2;
      comp.clear();
      ans += ok;
    }
  }
  cout << ans;
}
