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