#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > vc;
int vis[200005] = {0};
int dfs(int u) {
  vis[u] = 1;
  int ans = 1;
  if (vc[u].size() != 2) {
    ans = 0;
  }
  for (int i = 0; i < vc[u].size(); i++) {
    if (vis[vc[u][i]] == 0) {
      ans &= dfs(vc[u][i]);
    }
  }
  return ans;
}
int main() {
  int n, m, u, v;
  int ans = 0;
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  vc.resize(n);
  while (m--) {
    cin >> u >> v;
    u--;
    v--;
    vc[u].push_back(v);
    vc[v].push_back(u);
  }
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      ans += dfs(i);
    }
  cout << ans << endl;
  return 0;
}
