#include <bits/stdc++.h>
using namespace std;
int n, m;
int s, c;
int sum;
int main() {
  cin >> n >> m;
  vector<int> ans(n, -1);
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> s >> c;
    if (ans[s - 1] != c && ans[s - 1] != -1) {
      flag = 1;
      break;
    } else {
      ans[s - 1] = c;
    }
  }
  if (n > 1 && ans[0] <= 0) flag = 1;
  if (flag == 1)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) {
      if (ans[i] == -1 && i == 0) {
        sum += 1 * pow(10, n - i - 1);
      } else if (ans[i] == -1 && i != 0) {
        sum += 0;
      } else {
        sum += ans[i] * pow(10, n - i - 1);
      }
    }
    cout << sum << endl;
  }
}
