#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int q, w;
    cin >> q >> w;
    if (!a[q] || a[q] == w)
      a[q] = w;
    else {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!a[i]) {
      cout << -1;
      return 0;
    } else
      break;
  }
  for (int i = 1; i <= n; i++) cout << a[i];
}
