#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, result = 0, cnt = 0;
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<int> ans(n, 0);
  for (i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (i = 0; i < m - 1; i++) {
    ans.at(s.at(i) - 1) = c.at(i);
    for (int j = i + 1; j < m; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        result = -1;
        break;
      }
    }
    if (result != 0) {
      break;
    }
  }
  if (result == 0 && ans.at(0) != 0) {
    for (i = 0; i < n; i++) {
      cout << ans.at(i);
      cnt++;
    }
    if (cnt == n) {
      cout << endl;
    }
  } else {
    cout << "-1" << endl;
  }
}
