#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int INF = 9223372036854775807;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  long long int n, m;
  cin >> n >> m;
  vector<long long int> a(n, -1);
  for (long long int i = 0; i < (m); ++i) {
    long long int s, c;
    cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c) {
      a[s - 1] = c;
    } else {
      cout << -1 << '\n';
      return 0;
    }
    if (a[0] == 0 && a.size() > 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (long long int i = 0; i < (n); ++i) {
    if (a[i] == -1 && i == 0) {
      cout << 1;
    } else if (a[i] == -1) {
      cout << 0;
    } else {
      cout << a[i];
    }
  }
  cout << '\n';
}
