#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
vector<int> adj[300010];
vector<int> vis(300010, 0);
vector<int> par(300010, -1);
vector<int> disco(300010, -1);
vector<int> finis(300010, -1);
vector<int> type(300010, 0);
vector<int> val(300010, 0);
int flag = 0;
int cnt = 0;
void dfs(int a) {
  vis[a] = 1;
  if (adj[a].size() > 2) {
    flag = 1;
  }
  for (auto i : adj[a]) {
    if (vis[i] == 0) {
      par[i] = a;
      dfs(i);
    } else {
      if (i != par[a]) {
        cnt++;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      flag = 0;
      cnt = 0;
      dfs(i);
      if (flag == 0) {
        if (cnt != 0) {
          ans++;
        }
      }
    }
  }
  cout << ans << '\n';
}
