#include <bits/stdc++.h>
using namespace std;
int a[100], f[100];
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, f[q] = 1;
    else if (a[q] != w) {
      cout << -1;
      for (int j = i + 1; j <= m; j++) {
        int e, r;
        cin >> e >> r;
      }
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!a[i] && f[i]) {
      cout << -1;
      return 0;
    } else if (!a[i])
      a[i]++;
    else
      break;
  }
  long long s = 0;
  for (int i = 1; i <= n; i++) s = s * 10 + a[i];
  cout << s;
}
