#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, u, v, ans;
struct Edge {
  int nxt, to;
} edge[N << 1];
int head[N], edgeNum = 0, deg[N];
void addEdge(int from, int to) {
  edge[++edgeNum].nxt = head[from];
  edge[edgeNum].to = to;
  head[from] = edgeNum;
  deg[to]++;
}
bool vis[N], ok;
void dfs(int x) {
  vis[x] = 1;
  if (deg[x] != 2) ok = false;
  for (int i = head[x]; i; i = edge[i].nxt) {
    if (!vis[edge[i].to]) dfs(edge[i].to);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    addEdge(u, v);
    addEdge(v, u);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      ok = true;
      dfs(i);
      if (ok) ans++;
    }
  printf("%d\n", ans);
  return 0;
}
