#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans = 0;
int a[4];
bool v[4];
int main() {
  cin >> n >> m;
  for (int i = 1, s, c; i <= m; i++) {
    cin >> s >> c;
    if (s > n || s <= 0) {
      cout << "-1";
      return 0;
    }
    if (s == 1 && c == 0) {
      cout << "-1";
      return 0;
    }
    if (v[s]) {
      if (a[s] == c) continue;
      cout << "-1";
      return 0;
    }
    v[s] = 1;
    a[s] = c;
  }
  a[1] = max(a[1], 1);
  for (int i = 1, pw = 1; i <= n; i++) {
    ans += a[n - i + 1] * pw;
    pw *= 10;
  }
  cout << ans;
  return 0;
}
