#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int MAX = 200000;
int main() {
  int n, m;
  int a, b;
  int ans = 0;
  bool cond = true;
  cin >> n >> m;
  vector<P> digit(m);
  vector<int> num(n, -1);
  for (int i = 0; i < (m); i++) {
    cin >> a >> b;
    digit[i] = make_pair(a, b);
  }
  sort(digit.begin(), digit.end());
  for (int i = 0; i < (n); i++) {
    if (num[digit[i].first - 1] == -1) {
      num[digit[i].first - 1] = digit[i].second;
    } else if (num[digit[i].first - 1] != -1 &&
               num[digit[i].first - 1] == digit[i].second) {
      continue;
    } else {
      cond = false;
      break;
    }
  }
  if (num[0] == 0) cond = false;
  if (cond) {
    for (int i = 0; i < (n); i++) {
      if (num[i] >= 0) {
        ans += num[i] * pow(10, n - i - 1);
      }
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
