#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) {
    cout << 0 << 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]) {
      error = 1;
      break;
    }
    res[s[i] - 1] = c[i];
  }
  if (n > 1 && res[0] == 0) {
    error = 1;
  }
  if (res[0] == -1) res[0] = 1;
  for (int i = 0; i < (n); ++i) {
    if (res[i] == -1) res[i] = 0;
  }
  if (error == 1) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < (n); ++i) {
      cout << res[i];
    }
    cout << endl;
  }
  return 0;
}
