#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const long long mod = (int)1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int d[n];
  for (int i = 0; i < n; i++) d[i] = -1;
  for (int i = 0; i < n; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (d[s] != -1 && d[s] != c) {
      cout << -1;
      return 0;
    } else
      d[s] = c;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (d[i] == 0) {
        if (n != 1) {
          cout << -1;
          return 0;
        } else {
          cout << 0;
          return 0;
        }
      } else if (d[i] == -1)
        cout << 1;
      else
        cout << d[i];
    } else {
      if (d[i] == -1)
        cout << 0;
      else
        cout << d[i];
    }
  }
}
