#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ad[1000] = {};
  vector<pair<int, int> > gg;
  bool ok = false;
  for (int i = 1; i <= m; i++) {
    int a;
    int b;
    if (a == 1) {
      ok = true;
    }
    cin >> a >> b;
    gg.push_back(make_pair(a, b));
    ad[a].push_back(b);
  }
  if (ok == false) {
    cout << "-1" << endl;
    return 0;
  }
  ok = true;
  for (int i = 0; i < ad[1].size(); i++) {
    if (ad[1][i] == 0 || ad[1][i] != ad[1][0]) {
      cout << "-1" << endl;
    }
  }
  for (int i = 1; i <= 9; i++) {
    if (ad[i].size() > 0) {
      for (int j = 0; j < ad[i].size(); j++) {
        if (ad[i][j] != ad[i][0]) {
          cout << "-1" << endl;
        }
      }
    }
  }
  int ar[100] = {};
  for (int i = 0; i < gg.size(); i++) {
    ar[gg[i].first] = gg[i].second;
  }
  for (int i = 1; i <= n; i++) {
    cout << ar[i];
  }
  return 0;
}
