#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
int main() {
  int n, m;
  cin >> n >> m;
  int a[10];
  for (int i = 0; i < (int)(10); i++) {
    a[i] = 100;
  }
  int s, c;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      if (a[s] != 100 && a[s] != c) {
        cout << -1 << endl;
        return 0;
      }
      a[s] = c;
    }
  }
  int ans = 0, d = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != 100) {
      ans += a[i] * d;
    }
    d *= 10;
  }
  cout << ans << endl;
}
