#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  int s, c;
  for (long long i = (0); i < (m); i++) {
    cin >> s >> c;
    if (num[s - 1] != -1 and num[s - 1] != c) {
      cout << (-1) << endl;
      return 0;
    } else {
      num[s - 1] = c;
    }
  }
  if (num[0] == 0 and n != 1) {
    cout << (-1) << endl;
    return 0;
  } else if (num[0] == -1) {
    num[0] = 1;
  }
  int ans = 0;
  for (long long i = (0); i < (n); i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
    ans += num[i] * pow(10, n - i - 1);
  }
  cout << (ans) << endl;
}
