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