#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, x, y;
  int a[4] = {10, 10, 10, 10};
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    a[x] = min(a[x], y);
  }
  if (a[1] == 0 || a[1] == 10) {
    puts("-1");
    return 0;
  } else {
    for (int i = 1; i <= n; i++) {
      if (a[i] == 10)
        cout << 0;
      else
        cout << a[i];
    }
    puts("");
  }
  return 0;
}
