#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[10];
  memset(arr, -1, sizeof(arr));
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    if (arr[temp1] == -1) {
      arr[temp1] = temp2;
    } else {
      if (arr[temp1] != temp2) {
        flag = 1;
      }
    }
  }
  if (flag == 1 || arr[1] == 0)
    cout << -1 << endl;
  else {
    string s = "";
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        if (arr[i] == -1) {
          s += '1';
        } else
          s += '0' + arr[i];
      } else {
        if (arr[i] != -1)
          s += '0' + arr[i];
        else
          s += '0';
      }
    }
    cout << s << endl;
  }
}
