#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 1; i < 1000; ++i) {
    string S = to_string(i);
    if (S.size() != n) continue;
    bool elf = true;
    for (int i = 0; i < (m); ++i) {
      if (S[s[i]] != char(c[i] + '0')) elf = false;
    }
    if (elf) {
      cout << (i) << "\n";
      return 0;
    }
  }
  cout << (-1) << "\n";
  return 0;
}
