#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y;
int sb[23];
int main() {
  cin >> n >> m;
  bool flag = true;
  fill(sb, sb + 20, -1);
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (sb[x] != y && sb[x] != -1) flag = false;
    if (n != 1 && x == 1 && y == 0) flag = false;
    sb[x] = y;
  }
  if (m == 0) {
    cout << "0" << endl;
    return 0;
  }
  if (m > n) {
    cout << "-1" << endl;
    return 0;
  }
  if (flag == true) {
    int Out = 0;
    for (int i = 1; i <= n; i++) Out = Out * 10 + sb[i];
    cout << Out << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
