#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[11], c[11];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans = -1;
  for (int i = 1; i < 1000; i++) {
    vector<int> digits;
    int k = i;
    while (k) {
      digits.push_back(k % 10);
      k /= 10;
    }
    reverse(digits.begin(), digits.end());
    bool possible = true;
    for (int j = 0; j < m; j++) {
      if (s[j] >= digits.size() || digits[s[j]] != c[j]) possible = false;
    }
    if (possible) {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
