#include <bits/stdc++.h>
using namespace std;
int m, n, ru1, ru2;
set<int> sete;
bool dale = true;
int main() {
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < m; i++) {
    cin >> ru1 >> ru2;
    ru1--;
    if ((ru1 == 0 && ru2 == 0 && n != 1) ||
        (num[ru1] != -1 && ru2 != num[ru1])) {
      dale = false;
      break;
    } else {
      num[ru1] = ru2;
    }
  }
  for (int i = 0; i < n; i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  if (dale) {
    for (int i = 0; i < n; i++) {
      cout << num[i];
    }
    cout << "\n";
  } else {
    cout << "-1\n";
  }
  return 0;
}
