#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int dig(int n) {
  if (n == 0) return 1;
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> data(m, P(m, 0));
  for (int i = 0; i < (m); ++i) {
    cin >> data.at(i).first >> data.at(i).second;
  }
  sort(data.begin(), data.end());
  string s;
  if (n == 1) {
    s = '0';
    for (int i = 0; i < (m); ++i) {
      if (s[0] == '0') {
        s[0] = data.at(i).second + 48;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  } else if (n == 2) {
    s = "00";
    for (int i = 0; i < (m); ++i) {
      if (s[data.at(i).first - 1] == '0') {
        s[data.at(i).first - 1] = data.at(i).second + 48;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  } else if (n == 3) {
    s = "000";
    for (int i = 0; i < (m); ++i) {
      if (s[data.at(i).first - 1] == '0' ||
          s[data.at(i).first - 1] == data.at(i).second + 48) {
        s[data.at(i).first - 1] = data.at(i).second + 48;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (s[0] != '0')
    cout << s << endl;
  else
    cout << -1 << endl;
  return 0;
}
