#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  vector<set<int> > st(n + 1);
  int ans;
  st[0].insert(-1);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
    st[s[i]].insert(c[i]);
    if (st[s[i]].size() > 1) ans = -1;
    if (n != 1 && s[i] == 1 && c[i] == 0) ans = -1;
  }
  if (ans == -1) {
    cout << -1 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (!st[i].empty()) {
      for (int j = 0; j < (int)(10); j++) {
        if (st[i].count(j)) {
          sum *= 10;
          sum += j;
          break;
        }
      }
    } else {
      if (i == 1 && n != 1) {
        sum *= 10;
        sum += 1;
      } else {
        sum *= 10;
        sum += 0;
      }
    }
  }
  cout << sum << endl;
  return (0);
}
