#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  vector<int> ivs(10);
  vector<int> s(m);
  vector<int> check(9);
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int ins;
    cin >> ins;
    check.at(ins - 1)++;
    int inc;
    cin >> inc;
    if (check.at(ins - 1) > 1) {
      if (inc != c.at(ivs.at(ins))) flag = false;
    } else {
      s.at(i) = ins;
      c.at(i) = inc;
      ivs.at(ins) = i;
    }
  }
  if (!c.at(0) || !flag)
    cout << -1 << endl;
  else {
    int sum = 0;
    for (int i = 0; i < m; i++) {
      sum += c.at(i) * pow(10, n - s.at(i));
    }
    cout << sum << endl;
  }
}
