#include <bits/stdc++.h>
using namespace std;
int sc1() {
  int x;
  scanf("%d", &x);
  return x;
}
long long sc2() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int mod = 1e9 + 7;
const int inf = (int)2e9 + 5;
const long long Inf = (long long)1e18 + 5;
const int N = 2e6 + 5;
inline int add(int a, int b) {
  a += b;
  return a >= mod ? a - mod : a;
}
inline int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}
inline int mul(int a, int b) { return (long long)a * b % mod; }
std::vector<int> adj[N];
int vis[N];
int node, eg, pk;
std::map<pair<int, int>, int> mp;
void dfs(int s, int p = -1) {
  vis[s] = 1;
  if (adj[s].size() != 2) pk = false;
  node++;
  for (int i = 0; i < (int)adj[s].size(); i++) {
    int u = adj[s][i];
    if (!mp[{max(s, u), min(s, u)}]) {
      mp[{max(s, u), min(s, u)}] = 1;
      eg++;
    }
    if (!vis[u]) {
      dfs(u, s);
    }
  }
}
int solve() {
  int n = sc1(), m = sc1();
  for (int i = 0; i < m; i++) {
    int u = sc1();
    int v = sc1();
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      node = 0, eg = 0;
      pk = true;
      dfs(i);
      if (node == eg && pk) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    solve();
  }
  return 0;
}
