#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < (1000); ++i) {
    string a = to_string(i);
    bool flag = false;
    if (a.size() == n) {
      flag = true;
      for (int j = 0; j < (m); ++j) {
        if (int(a[s[j] - 1]) != c[j]) flag = false;
      }
    }
    if (flag == true) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
