#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> v(n, 0);
  bool a[3] = {false};
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    if (v[temp1 - 1] == temp2 || a[temp1 - 1] == false) {
      a[temp1 - 1] = true;
      v[temp1 - 1] = temp2;
    } else {
      ok = false;
    }
  }
  if (ok) {
    if (n == 1) {
      cout << v[0];
    } else {
      if (v[0] == 10) {
        cout << "-1";
      } else {
        for (int i = 0; i < n; i++) {
          if (i == 0 && v[0] == 0) {
            continue;
          }
          cout << v[i];
        }
      }
    }
  } else {
    cout << -1;
  }
  return 0;
}
