#include <bits/stdc++.h>
using namespace std;
int64_t INF = 1e18;
int inf = 1e9;
int64_t mod = 1e9 + 7;
typedef struct {
  bool L, R;
} p_t;
string to_str(int64_t x) {
  string s = "";
  while (x > 0) {
    char a = '0' + (x % 10);
    s = a + s;
    x /= 10;
  }
  return s;
}
int main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> s(m), c(m);
  for (int64_t i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int64_t x = 1;
  for (int64_t i = 0; i < n; i++) {
    x *= 10;
  }
  for (int64_t i = x / 10; i < x; i++) {
    bool check = true;
    string t = to_str(i);
    for (int64_t j = 0; j < m; j++) {
      int64_t d = t[s[j] - 1] - '0';
      if (d != c[j]) {
        check = false;
      }
    }
    if (check) {
      cout << (i) << '\n';
      return 0;
    }
  }
  cout << (-1) << '\n';
  return 0;
}
