#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int MAXN = 1e7 + 1;
const long long int INF = 2e18;
const long double PI = acos(-1);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    ;
    vector<int> a(n, -1);
    bool ok = 1;
    for (int i = 0; i < (m); ++i) {
      int s, c;
      cin >> s >> c;
      ;
      s--;
      if ((a[s] != -1 && a[s] != c) || (s == 0 && n > 1))
        ok = 0;
      else
        a[s] = c;
    }
    if (ok)
      for (int i = 0; i < (n); ++i)
        if (a[i] != -1)
          cout << a[i];
        else
          cout << 1;
    else
      cout << -1;
  }
  return 0;
}
