#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1e5 + 5;
const long long MOD = 1e9 + 7;
int main() {
  bool flag = 1;
  int e[10];
  memset(e, -1, sizeof(e));
  int n, m, s, c, ans = 0;
  cin >> n >> m;
  for (int i = (1); i <= (m); i++) {
    cin >> s >> c;
    if (e[s] != -1 && e[s] != c) flag = 0;
    e[s] = c;
  }
  if (!flag) {
    cout << "-1\n";
    return 0;
  }
  if (n == 1) {
    cout << e[1] << endl;
  } else {
    if (!e[1]) {
      cout << "-1\n";
      return 0;
    }
    for (int i = (1); i <= (n); i++) {
      if (e[i] != -1)
        ans = ans * 10 + e[i];
      else
        ans *= 10;
    }
    cout << ans << endl;
  }
  return 0;
}
