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