#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> tmp(n, -1);
  int s[m], c[m];
  bool flg = true;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (tmp[s[i] - 1] == -1 || tmp[s[i] - 1] == c[i]) {
      tmp[s[i] - 1] = c[i];
    } else
      flg = false;
  }
  if (flg == true && tmp[0] != 0) {
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        if (tmp[i] == -1)
          cout << 1;
        else
          cout << tmp[i];
      } else {
        if (tmp[i] == -1)
          cout << 0;
        else
          cout << tmp[i];
      }
    }
  } else
    cout << -1 << endl;
  return 0;
}
