#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int a[3];
  bool ans = false;
  for (int i = max(0, (int)pow(10, n - 1)); i < pow(10, n); i++) {
    a[2] = i % 10;
    a[1] = (i / 10) % 10;
    a[0] = (i / 100) % 10;
    for (int i = 0; i < m; i++) {
      if (a[s[i] - 1] == c[i])
        ans = true;
      else {
        ans = false;
        break;
      }
    }
    if (ans) break;
  }
  if (ans) {
    for (int i = 0; i < n; i++) cout << a[i];
    cout << endl;
  } else
    cout << -1 << endl;
}
