#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);
}
bool Mainl() {
  int n, m;
  cin >> n >> m;
  set<pair<int, int> > s;
  for (long long i = 0; i < m; i++) {
    pair<int, int> p;
    cin >> p.first >> p.second;
    if (p.first == 1 && p.second == 0) {
      return false;
    }
    s.insert(p);
  }
  if (n == 1) {
    if (s.size() > 1) return false;
    if (s.size() == 1)
      for (auto x : s) cout << x.second << endl;
    else
      cout << 0 << endl;
    return true;
  }
  vector<int> ans(n, 0);
  ans[0] = 1;
  int ok[4] = {0, 0, 0, 0};
  for (auto x : s) {
    if (ok[x.first]) {
      return false;
    }
    ok[x.first] = 1;
    ans[x.first - 1] = x.second;
  }
  for (auto x : ans) cout << x;
  cout << endl;
  return true;
}
void Main() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Main();
  if (!Mainl()) {
    cout << -1 << endl;
  }
  return 0;
}
