#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  bool flag = true;
  vector<char> ans(n);
  vector<bool> mark(n, false);
  int od, num;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    od = s[i] - 1;
    num = c[i];
    if (mark[od] == true && ans[od] != '0' + num) {
      flag = false;
      break;
    }
    if (od == 0 && num == 0) {
      flag = false;
      break;
    }
    ans[od] = '0' + num;
    mark[od] = true;
  }
  if (flag == true) {
    for (int i = 0; i < n; i++) {
      if (mark[i] == false) {
        ans[i] = '0';
      }
      cout << ans[i];
    }
    cout << endl;
  } else if (flag == false) {
    cout << -1 << endl;
  }
}
