#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> data(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if ((data[a - 1] == 0 || data[a - 1] == b) && (a - 1) != 0)
      data[a - 1] = b;
    else {
      cout << "-1";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) cout << data[i];
}
