#include <bits/stdc++.h>
using namespace std;
vector<int> X[200010];
int vis[200010];
int check(int i, int p) {
  int t = 0, ans = 0;
  vis[i] = 1;
  for (int j = 0; j < X[i].size(); ++j) {
    if (X[i][j] == p) {
      t++;
      continue;
    }
    if (vis[X[i][j]]) {
      t++;
      if (p != -1) ans = 1;
      continue;
    }
    ans = check(X[i][j], i);
    t++;
  }
  if (ans == 1 && t == 2) return ans;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, x, y;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    X[x].push_back(y);
    X[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0) ans += check(i, -1);
  }
  cout << ans << endl;
  return 0;
}
