#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1000000000;
std::string ten_to_n(int ten, int base) {
  if (ten == 0) return "0";
  std::string s;
  while (ten) {
    int amari = ten % base;
    char c = '0' + amari;
    s.push_back(c);
    ten /= base;
  }
  std::reverse(s.begin(), s.end());
  return s;
}
long long powe(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp & 1) res = res * base;
    base = base * base;
    exp >>= 1;
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> keta(6, -1);
  bool res = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (keta[s] != c && keta[s] != -1) res = false;
    keta[s] = c;
  }
  string ans(10, 'A');
  for (int i = powe(10, n - 1); i < powe(10, n); i++) {
    string s = ten_to_n(i, 10);
    bool f = false;
    for (int j = 0; j < n; j++) {
      if (keta[j] + '0' != s[j] && keta[j] != -1) f = true;
    }
    if (!f) {
      for (int j = 0; j < n; j++) {
        ans[j] = (keta[j] == -1 ? '0' : keta[j] + '0');
      }
      break;
    }
  }
  if (ans[0] == '0' && n != 1) ans[0] = '1';
  if (ans[0] == 'A' || !res)
    cout << -1;
  else {
    for (int i = 0; i < n; i++) cout << ans[i];
  }
  cout << endl;
}
