#include <bits/stdc++.h>
using namespace std;
int syc(long i, long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m], ans[n];
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 1; i < m; i++) {
    for (int j = 0; j <= i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == 0) {
    ans[0] = 1;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
