#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY = 2147483647;
int main() {
  int n, m, s, c, A[3];
  bool ans = true;
  cin >> n >> m;
  for (int i = 0; i < (3); ++i) A[i] = -1;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (A[s - 1] == -1)
      A[s - 1] = c;
    else if (A[s - 1] != c)
      ans = false;
  }
  int x = 0;
  if (ans) {
    for (int i = 0; i < (n); ++i) x += max(0, A[i]) * pow(10, n - 1 - i);
    if (x > 0)
      cout << x << endl;
    else
      cout << -1 << endl;
  } else
    cout << -1 << endl;
}
