#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);
int char_to_int(char c) { return c - '0'; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  if (n == 1) {
    bool ok = true;
    string num = "0";
    for (int j = 0; j < (int)(m); j++) {
      if (char_to_int(num[s[j] - 1]) != c[j]) ok = false;
    }
    if (ok) ans = 0;
  }
  for (int i = (pow(10, n - 1)); i < (pow(10, n)); i++) {
    bool ok = true;
    string num = to_string(i);
    for (int j = 0; j < (int)(m); j++) {
      if (char_to_int(num[s[j] - 1]) != c[j]) ok = false;
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
