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