#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
vector<int> s(10);
vector<int> c(10);
int main(int argc, char **argv) {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  bool flag = true;
  string str;
  for (int i = 0; i < n; ++i) str += "0";
  vector<int> his;
  for (int i = 0; i < m; ++i) {
    int digit = s[i];
    int num = c[i];
    if (str[digit - 1] != '0' && str[digit - 1] != '0' + num) {
      flag = false;
      break;
    }
    string tmp = to_string(num);
    str.replace(digit - 1, 1, tmp);
  }
  str = to_string(stoi(str));
  if (str.size() != n) flag = false;
  if (flag)
    std::cout << str << std::endl;
  else
    std::cout << -1 << std::endl;
}
