#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1000000007;
double eps = 1e-12;
#define ln "\n"
#define printVector(a)                                                         \
  for (int i = 0; i < a.size(); i++) {                                         \
    cout << a[i] << " ";                                                       \
  }                                                                            \
  cout << ln;
#define print_array(a, n)                                                      \
  for (int i = 0; i < n; i++) {                                                \
    cout << a[i] << " ";                                                       \
  }                                                                            \
  cout << ln;
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define take_vector(a)                                                         \
  for (auto &x : a)                                                            \
    cin >> x;
#define take_array(a, n)                                                       \
  for (int i = 0; i < n; i++) {                                                \
    cin >> a[i];                                                               \
  }
#define take_matrix(a, m, n)                                                   \
  for (int i = 0; i < m; i++) {                                                \
    for (int j = 0; j < n; j++) {                                              \
      cin >> a[i][j];                                                          \
    }                                                                          \
  }
#define print_matrix(a, m, n)                                                  \
  for (int i = 0; i < m; i++) {                                                \
    for (int j = 0; j < n; j++) {                                              \
      cout << a[i][j] << " ";                                                  \
    }                                                                          \
    cout << ln;                                                                \
  }
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / gcd(a, b)) * b
#define count(a, x) count(a.begin(), a.end(), x)
#define sum(a) accumulate(a.begin(), a.end(), 0)
#define max_ele(a) *max_element(a.begin(), a.end())
#define min_ele(a) *min_element(a.begin(), a.end())

// Define Objects & Functions Here

bool bipart(int n, vector<int> adj[], vector<int> &color) {
  for (int i = 1; i <= n; i++) {
    if (color[i] == -1) {
      color[i] = 0;
      queue<int> q;
      q.push(i);

      while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (auto it : adj[node]) {
          if (color[it] != -1 && color[it] != color[node] xor 1)
            return false;
          if (color[it] == -1) {
            q.push(it);
            color[it] = color[node] xor 1;
          }
        }
      }
    }
  }
  return true;
}

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast_cin();
  // Write Your Code Here
  int n, m;
  cin >> n >> m;
  vector<int> adj[n + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vector<int> color(n + 1, -1);
  bool x = bipart(n, adj, color);
  cout << x;

  return 0;
}
