#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = -1;
  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 f = to_string(i);
    bool ff = true;
    for (int(j) = 0; (j) < (m); (j)++) {
      if (i < 100 && s[j] >= 3) {
        ff = false;
        break;
      }
      if (i < 10 && s[j] == 2) {
        ff = false;
        break;
      }
      if (i < 10 && s[j] == 3) {
        ff = false;
        break;
      }
      if (f.at(s[j] - 1) - '0' != c[j]) ff = false;
    }
    if (ff && f.length() == n) {
      ans = i;
    }
  }
  cout << ans << endl;
}
