#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < 1000; ++i) {
    int digit[3];
    digit[0] = i / 100;
    digit[1] = (i % 100) / 10;
    digit[2] = i % 10;
    if (!((n == 1 && digit[0] == 0 && digit[1] == 0) ||
          (n == 2 && digit[0] == 0 && digit[1] != 0) ||
          (n == 3 && digit[0] != 0))) {
      continue;
    }
    bool isSuccess = true;
    for (int j = 0; j < m; ++j) {
      if (s[j] > n) {
        continue;
      }
      if (digit[s[j] - 1] != c[j]) {
        isSuccess = false;
        break;
      }
    }
    if (isSuccess) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
