#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int INF = 1000000009;
int main() {
  int n, m;
  cin >> n >> m;
  vector<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 str = to_string(i);
    int cnt = s.size();
    bool flag = true;
    for (int j = 0; j < m; j++) {
      if (str[s[j]] != char(c[i] + '0')) {
        flag = false;
      }
    }
    if (cnt == n && flag) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << endl;
}
