#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  vector<int> res(3);
  for (int i = 0; i < (3); ++i) res[i] = -1;
  int error = 0;
  for (int i = 0; i < (m); ++i) {
    if ((res[s[i] - 1] == -1) || (res[s[i] - 1] == c[i])) {
      res[s[i] - 1] = c[i];
    } else {
      error = 1;
    }
  }
  if (error) {
    cout << -1 << endl;
    return 0;
  }
  if (n >= 2 && res[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n >= 2 && res[0] == -1) {
    res[0] = 1;
  } else if (res[0] == -1) {
    res[0] = 0;
  }
  if (res[1] == -1) {
    res[1] = 0;
  }
  if (res[2] == -1) {
    res[2] = 0;
  }
  for (int i = 0; i < (n); ++i) {
    cout << res[i];
  }
  cout << endl;
  return 0;
}
