#include <bits/stdc++.h>
using namespace std;
int reverse(int num) {
  int rev = 0;
  while (num > 0) {
    rev = rev * 10 + num % 10;
    num /= 10;
  }
  return rev;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) cin >> s.at(i) >> c.at(i);
  for (int i = 0; i < (m - 1); ++i) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      } else if (s[i] == s[j]) {
        s.erase(s.begin() + j);
        c.erase(c.begin() + j);
        j--;
        m--;
      }
    }
  }
  m = s.size();
  int ans = 0;
  for (int i = 0; i < (m); ++i) {
    ans += c[i] * pow(10, s[i] - 1);
  }
  cout << reverse(ans) << endl;
  return 0;
}
