#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    set<long long> vx[n + 1];
    long long no1, no2;
    bool filled[n + 1];
    memset(filled, false, sizeof(filled));
    for (long long i = 0; i < m; i++) {
      cin >> no1 >> no2;
      vx[no1].insert(no2);
      filled[no1] = true;
    }
    bool flag = true;
    for (long long i = 1; i <= n; i++) {
      if (vx[i].size() > 1) {
        flag = false;
      }
    }
    if (!flag) {
      cout << -1 << "\n";
    } else {
      long long ans[n + 1];
      memset(ans, 0, sizeof(ans));
      for (long long i = 1; i <= n; i++) {
        if (filled[i]) {
          set<long long>::iterator it = vx[i].begin();
          long long val = *it;
          ans[i] = val;
        }
      }
      for (long long i = 1; i <= n; i++) {
        if (!filled[i]) {
          if (i == 1) {
            ans[i] = 1;
          } else {
            ans[i] = 0;
          }
        }
      }
      if (n > 1) {
        bool flag = true;
        if (ans[1] == 0) {
          for (long long i = 2; i <= n; i++) {
            if (ans[i] != 0) {
              flag = false;
              break;
            }
          }
          if (!flag) {
            cout << -1 << "\n";
          } else {
            for (long long i = 1; i <= n; i++) {
              cout << ans[i];
            }
          }
        } else {
          for (long long i = 1; i <= n; i++) {
            cout << ans[i];
          }
          cout << "\n";
        }
      } else {
        for (long long i = 1; i <= n; i++) {
          cout << ans[i];
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
