#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;
struct node {
  int from;
  int to;
  int next;
  int cost;
} edge[maxn << 1];
int head[maxn], tot;
int n, m;
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
void addedge(int u, int v, int cost) {
  edge[tot].from = u;
  edge[tot].to = v;
  edge[tot].cost = cost;
  edge[tot].next = head[u];
  head[u] = tot++;
}
int vis[maxn];
int point, edg;
void dfs(int x, int fa) {
  vis[x] = true;
  point++;
  int degree = 0;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    ++degree;
    edg++;
    if (to == fa) continue;
    if (vis[to]) continue;
    dfs(to, x);
  }
  if (degree != 2) {
    point = INT_MIN;
  }
}
void solve() {
  memset(vis, 0, sizeof(vis));
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    point = edg = 0;
    dfs(i, -1);
    if (point == edg / 2) ans++;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (cin >> n >> m) {
    init();
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      addedge(u, v, 0);
      addedge(v, u, 0);
    }
    solve();
  }
  return 0;
}
