#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int keta(int n) {
  int ret = 0;
  while (n) {
    ret++;
    n /= 10;
  }
  return ret;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, s, c, ans = -1, f;
  cin >> n >> m;
  vector<pair<int, int> > d(m);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    d[i].first = s, d[i].second = c;
  }
  for (int i = 0; i < 1000; i++) {
    f = 1;
    if (n == keta(i)) {
      string s = to_string(i);
      for (int j = 0; j < m; j++) {
        if (s[d[j].first] != ('0' + d[j].second)) {
          f = 0;
        }
      }
      if (f) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
}
