#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[5];
  int c[5];
  for (size_t i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int an[3] = {10, 10, 10};
  int at = 0;
  for (size_t i = 0; i < n; i++) {
    for (size_t ii = 0; ii < m; ii++) {
      if (s[ii] == i + 1) {
        if (an[i] == 10) {
          an[i] = c[ii];
        } else {
          if (an[i] != c[ii]) {
            at = 1;
          }
        }
      }
    }
  }
  if (an[0] == 0 && n != 1) {
    at = 1;
  }
  if (at == 1) {
    cout << "-1" << endl;
  } else {
    if (m == 0)
      cout << 0;
    else {
      for (size_t i = 0; i < n; i++) {
        if (an[i] == 10)
          cout << 0;
        else
          cout << an[i];
      }
    }
    cout << endl;
  }
  return 0;
}
