#include <bits/stdc++.h>
using namespace std;
void solve1() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  string num = "";
  vector<bool> nums(n);
  for (int i = 0; i < n; i++) {
    num += '0';
    nums[i] = true;
  }
  for (int i = 0; i < m; i++) {
    if (nums[s[i] - 1] || num[s[i] - 1] == c[i] + '0') {
      num[s[i] - 1] = c[i] + '0';
      nums[s[i] - 1] = false;
    } else {
      num = "-1";
      break;
    }
  }
  if (num[0] == '0') {
    num = "-1";
  }
  cout << num << endl;
}
int main() { solve1(); }
