#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[3], c[5];
  int n, m;
  cin >> n >> m;
  for (int(i) = 0; (i) < (m); (i)++) {
    cin >> s[i] >> c[i];
  }
  int tf = 1;
  for (int(i) = 0; (i) < (m); (i)++) {
    for (int(j) = 0; (j) < (m); (j)++) {
      if (i != j && s[i] == s[j] && c[i] != c[j]) {
        tf = 0;
      }
    }
  }
  int q = n;
  if (n < m) {
    q = m;
  }
  vector<int> x(q);
  for (int(i) = 0; (i) < (q); (i)++) {
    x.at(i) = 0;
  }
  if (tf == 1) {
    for (int(i) = 0; (i) < (m); (i)++) {
      x.at(s[i] - 1) = c[i];
    }
    if (x.at(0) != 0) {
      for (int(i) = 0; (i) < (n); (i)++) {
        cout << x.at(i);
      }
    } else {
      cout << -1;
    }
    cout << endl;
  } else if (tf == 0) {
    cout << -1 << endl;
  }
}
