#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, x, y, z, m, q, h, r, timer, mx, l;
long long a[300500];
long long b[1005000], t[1005000], used[1005000];
vector<long long> g[200500];
string s;
set<long long> is_here;
void dfs(long long v) {
  if (used[v]) return;
  used[v] = 1;
  l++;
  if (g[v].size() != 2) {
    mx = 0;
  }
  for (int i = 0; i < g[v].size(); i++) {
    dfs(g[v][i]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      mx = 1;
      l = 0;
      dfs(i);
      if (l >= 3 && mx == 1) ans++;
    }
  cout << ans << endl;
  return 0;
}
