#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int main() {
  int n, m, s, tmpc, c[5];
  cin >> n >> m;
  bool ans = true;
  for (int i = 1; i <= n; i++) {
    c[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> tmpc;
    if (c[s] != -1 && c[s] != tmpc) {
      ans = false;
    }
    c[s] = tmpc;
  }
  if (n != 1 && c[1] == 0) {
    ans = false;
  }
  if (!ans) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (c[i] == -1 && i != 1) {
      cout << 0;
    } else if (c[i] == -1 && i == 1) {
      cout << 1;
    } else {
      cout << c[i];
    }
  }
  cout << endl;
}
