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