#include <bits/stdc++.h>
using namespace std;
bool vis[200002], fl;
vector<vector<int> > v(200002);
void dfs(int x) {
  vis[x] = 1;
  if (v[x].size() != 2) fl = 0;
  for (int i = 0; i < v[x].size(); i++)
    if (vis[v[x][i]] == 0) dfs(v[x][i]);
}
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int A, B;
    cin >> A >> B;
    v[A].push_back(B);
    v[B].push_back(A);
  }
  for (int i = 1; i <= n; i++) {
    fl = 1;
    if (!vis[i]) {
      dfs(i);
      if (fl) ans++;
    }
  }
  cout << ans;
}
