#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int arr[5];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, m, a, b;
  cin >> n >> m;
  memset(arr, -1, sizeof(arr));
  bool ok = 1;
  while (m--) {
    cin >> a >> b;
    if (a > n) {
      ok = 0;
      break;
    }
    if (arr[a] != -1 && arr[a] != b) {
      ok = 0;
      break;
    }
    arr[a] = b;
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i] == -1) {
      arr[i] = 0;
    }
  }
  if (n > 1 && arr[1] == 0) {
    ok = 0;
  }
  if (ok) {
    for (int i = 1; i <= n; i++) {
      cout << arr[i];
    }
    cout << '\n';
  } else {
    cout << -1 << '\n';
  }
}
