#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, flag = 0;
  cin >> n >> m;
  vector<int> v(n, -1);
  vector<int> s(m);
  vector<int> c(m);
  for (int i = int(0); i <= int(m - 1); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = int(0); i <= int(m - 1); i++) {
    if (s[i] == 0 && c[i] == 0) {
      flag = 1;
      break;
    } else {
      if (v[s[i]] == -1 || v[s[i]] == c[i])
        v[s[i]] = c[i];
      else {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0) {
    if (v[0] == -1) v[0] = 1;
    for (int i = int(1); i <= int(n - 1); i++) {
      if (v[i] == -1) {
        v[i] = 0;
      }
    }
    for (int i = int(0); i <= int(n - 1); i++) cout << v[i];
  } else
    cout << -1 << "\n";
  return 0;
}
