#include <bits/stdc++.h>
using namespace std;
int n, m, head[200010], tot, a[200010], ans, num = 0;
bool vis[200010];
struct ed {
  int to, next;
} edge[400010];
void addedge(int u, int v) {
  edge[++tot].next = head[u];
  edge[tot].to = v;
  head[u] = tot;
}
void dfs(int now) {
  if (a[now] != 2) {
    num = 1;
  }
  for (int i = head[now]; i; i = edge[i].next) {
    if (vis[edge[i].to]) continue;
    vis[edge[i].to] = 1;
    dfs(edge[i].to);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
    ++a[u];
    ++a[v];
  }
  for (int i = 1; i <= n; ++i) {
    num = 0;
    if (vis[i] == 1) continue;
    vis[i] = 1;
    dfs(i);
    if (!num) {
      ++ans;
    }
  }
  printf("%d", ans);
  return 0;
}
