#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n + 1, 0);
  bool possible = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num[s] != 0 && num[s] != c) {
      possible = false;
    }
    if (s == 0 && c == 0) {
      possible = false;
    }
    num[s] = c;
  }
  if (!possible) {
    cout << -1 << endl;
    return 0;
  }
  if (num[0] == 0) {
    num[0] = 1;
  }
  for (int i = 0; i < n; i++) cout << num[i];
  cout << endl;
}
