#include <bits/stdc++.h>
using namespace std;
const long long INF = long long(1e18) + 1;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  return (b <= 0) ? a : gcd(b, a % b);
}
unsigned long long int lcm(unsigned long long int a, unsigned long long int b) {
  return a * b / gcd(a, b);
}
void Main() {
  int n, m;
  cin >> n >> m;
  set<pair<int, int> > se;
  vector<int> ans(n, 0), c(n, 0);
  ans[0] = 1;
  for (long long i = 0; i < m; i++) {
    pair<int, int> a;
    cin >> a.first >> a.second;
    se.insert(a);
  }
  if (se.size() > 3) {
    cout << -1 << endl;
    return;
  }
  for (auto x : se) {
    if (x.first == 1 && x.second == 0) {
      cout << -1 << endl;
      return;
    }
    if (x.first == 1) {
      ans[0] = x.second;
      if (c[0]) {
        cout << -1 << endl;
        return;
      }
      c[0] = 1;
    }
    if (x.first == 2) {
      ans[1] = x.second;
      if (c[1]) {
        cout << -1 << endl;
        return;
      }
      c[1] = 1;
    }
    if (x.first == 3) {
      ans[2] = x.second;
      if (c[2]) {
        cout << -1 << endl;
        return;
      }
      c[2] = 1;
    }
  }
  for (auto x : ans) cout << x;
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Main();
  return 0;
}
