#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
const ll mod = 1e9 + 7;
const ll inf = 1e10;
const double pi = 3.141592;
ll gcd(ll a, ll b) { return (b != 0) ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
template <class T>
bool contain(const string& s, const T& v) {
  return s.find(v) != std::string::npos;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> k(n + 1);
  for (int i = 0; i < (int)m; i++) {
    int s, c;
    cin >> s >> c;
    if (k[s] == 0)
      k[s] = c;
    else if (k[s] != c) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (k[1] == 0) {
    cout << -1 << "\n";
    return 0;
  }
  int ans = 0;
  for (int i = 1; i < (int)n + 1; i++) ans += k[i] * pow(10, n - i);
  cout << ans << "\n";
  return 0;
}
