#include <bits/stdc++.h>
using namespace std;
void file() {}
int tc;
const int N = 1e6 + 5, M = 2e6 + 5, MOD = 1e9 + 7, OO = 1e9;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  std::vector<int> ans(n, -1);
  for (int i = 0, s, c; i < n; i++) {
    cin >> s >> c;
    s--;
    if (ans[s] != -1 && c != ans[s]) return cout << "-1\n", 0;
    ans[s] = c;
  }
  for (int i = 0; i < ((int)(ans).size()); i++) {
    if (ans[i] == -1) {
      if (i)
        cout << 0;
      else
        return cout << "-1\n", 0;
    } else
      cout << ans[i];
  }
}
