#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<pair<int, int>> t;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    t.emplace_back(s, c);
  }
  sort(t.begin(), t.end());
  vector<int> a(n, -1);
  for (int i = 0; i < (m); i++) {
    if (a[t[i].first] == -1 || a[t[i].first] == t[i].second)
      a[t[i].first] = t[i].second;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < (n); i++) {
      if (i == 0 && a[i] == -1)
        cout << 1;
      else if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
    cout << endl;
  }
  return 0;
}
