#include <bits/stdc++.h>
using namespace std;
bool flag = true;
int n, m, b, c;
struct num {
  int a, b;
} x[50];
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> b >> c;
    if (x[b].b != 0 && x[b].a != c)
      flag = false;
    else {
      x[b].a = c;
      x[b].b = 1;
    }
  }
  if (flag == false || (x[1].b == 1 && x[1].a == 0 && n > 1)) {
    cout << -1;
  } else if (n > 1) {
    if (x[1].a == 0)
      cout << 1;
    else
      cout << x[1].a;
    for (int i = 1; i <= n; i++) cout << x[i].a;
  } else
    cout << x[1].a;
}
