#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  bool flag = true;
  cin >> n >> m;
  vector<int> a(n, 0);
  vector<bool> b(n, false);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (b[s - 1] == false) {
      a[s - 1] = c;
      b[s - 1] = true;
    } else if (b[s - 1] == true && a[s - 1] == c)
      continue;
    else
      flag = false;
  }
  if (flag) {
    if (n != 1 && a[0] != 0)
      for (int i = 0; i < (int)(n); i++) cout << a[i];
    else if (n == 1)
      cout << a[0];
    else if (n != 1 && a[0] == 0)
      cout << -1;
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
