#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < m; j++) {
        if (c[j] != i) {
          break;
        }
        if (j = m - 1) {
          ans = i;
          goto END;
        }
      }
    }
  } else {
    for (int i = pow(10, n); i < pow(10, n + 1); i++) {
      string str = to_string(i);
      for (int j = 0; j < m; j++) {
        if ((int)str[s[j] - 1] != c[j]) {
          break;
        }
        if (j = m - 1) {
          ans = i;
          goto END;
        }
      }
    }
  }
END:
  cout << ans;
}
