#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int ans, pre[N], degree[N];
struct edge {
  int u, v;
} node[N];
int fathersearch(int x) {
  int i = x, j = x, temp;
  while (pre[i] != i) i = pre[i];
  while (j != i) {
    temp = pre[j];
    pre[j] = i;
    j = temp;
  }
  return i;
}
void join(int x, int y) {
  int fx = fathersearch(x), fy = fathersearch(y);
  if (fx != fy)
    pre[fx] = fy;
  else
    ans++;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) pre[i] = i;
  ans = 0;
  struct edge e[m];
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &node[i].u, &node[i].v);
    degree[node[i].u]++;
    degree[node[i].v]++;
  }
  for (int i = 1; i <= m; i++) {
    if (degree[node[i].u] == 2 && degree[node[i].v] == 2)
      join(node[i].u, node[i].v);
  }
  printf("%d\n", ans);
  return 0;
}
