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