#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> G[maxn];
bool vis[maxn];
int n, m, u, v, ans;
int V, D, cnt;
void dfs(int u) {
  vis[u] = true;
  V++;
  D += G[u].size();
  if (G[u].size() == 2) {
    cnt++;
  }
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (false == vis[v]) {
      dfs(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m;
  while (m--) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (true == vis[i]) {
      continue;
    }
    V = D = cnt = 0;
    dfs(i);
    if (V == D / 2 && V == cnt) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
