#include <bits/stdc++.h>
using namespace std;
vector<int> ar[200005], ans;
int vis[200005], deg[200005];
void addEdge(int u, int v) {
  ar[u].push_back(v);
  ar[v].push_back(u);
  deg[u]++;
  deg[v]++;
}
void dfs(int node) {
  vis[node] = 1;
  ans.push_back(node);
  for (int child : ar[node]) {
    if (!vis[child]) dfs(child);
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, u, v, cnt = 0, t;
  cin >> n >> m;
  while (m--) {
    cin >> u >> v;
    addEdge(u, v);
  }
  for (long long i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      ans.clear();
      dfs(i);
      t = 0;
      for (int node : ans) {
        if (deg[node] != 2) {
          t = 1;
          break;
        }
      }
      if (!t) cnt++;
    }
  }
  cout << cnt;
}
