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