#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll INF = 1e9 + 9;
const double PI = 4.0 * atan(1.0);
ll powmod(ll a, ll b, const ll MOD) {
  ll res = 1;
  a %= MOD;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0);
  bool ok = true;
  set<pair<int, int>> s;
  while (m > 0) {
    int ss, cc;
    cin >> ss >> cc;
    if (ss == 1 && cc == 0 && n > 1) ok = false;
    s.insert({ss, cc});
    --m;
  }
  if (!ok) {
    cout << "-1";
    return 0;
  }
  if (s.size() <= n) {
    for (auto p : s) {
      for (auto pp : s) {
        if (p != pp && p.first == pp.first && p.second != pp.second) ok = false;
      }
    }
    if (!ok)
      cout << "-1";
    else {
      for (auto p : s) a[p.first] = p.second;
      for (int i = 1; i <= n; ++i) cout << a[i];
    }
  } else
    cout << "-1";
  return 0;
}
