#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool flag = true;
  cin >> n >> m;
  int buf[n];
  for (int i = 0; i < n; i++) buf[i] = -1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (buf[s - 1] == -1 || buf[s - 1] == c)
      buf[s - 1] = c;
    else
      flag = false;
  }
  if (flag) {
    if (buf[0] == 0) cout << "-1" << endl;
    for (int i = 0; i < n; i++) {
      if (buf[i] == -1) {
        if (i == 0)
          buf[i] = 1;
        else
          buf[i] = 0;
      }
    }
    int buf1 = 0;
    for (int i = 0; i < n; i++) {
      buf1 += buf[i] * (int)pow(10.0, n - 1 - i);
    }
    cout << buf1 << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
