#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
vector<int> E[maxn + 5];
int n, m, cnt;
bool vis[maxn + 5], vs[maxn + 5];
int ind[maxn + 5];
bool dfs(int x, int p, int dis) {
  if (ind[x] != 2) return false;
  if (x == p && dis >= 3) return true;
  vis[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    if (!vis[E[x][i]] || (E[x][i] == p && dis >= 3))
      return dfs(E[x][i], p, dis + 1);
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
    ind[v]++;
    ind[u]++;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    if (dfs(i, i, 1)) {
      if (ind[i] == 2) cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
