#include <bits/stdc++.h>
using namespace std;
vector<int> cc[200005];
bool vis[200005];
vector<int> gr[200005];
void dfs(int x, int i) {
  vis[x] = true;
  cc[i].push_back(x);
  for (auto ed : gr[x]) {
    if (vis[ed] == false) dfs(ed, i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, a, b;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  memset(vis, false, sizeof(vis));
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      dfs(i, cnt);
      cnt++;
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int f = 1;
    for (int j = 0; j < cc[i].size(); j++) {
      if (gr[cc[i][j]].size() != 2) {
        f = 0;
        break;
      }
    }
    if (cc[i].size() >= 3 && f == 1) ans++;
  }
  cout << ans;
}
