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