#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n, 0);
  vector<int> count(n, 0);
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a <= n) {
      if (count[a - 1] == 0) {
        vec[a - 1] = b;
        count[a - 1] = 1;
      } else {
        if (vec[a - 1] != b) flag = false;
      }
    } else
      flag = false;
  }
  if (flag == true && vec[0] != 0) {
    for (int i : vec) {
      cout << i;
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
