#include <bits/stdc++.h>
using namespace std;
double const EPS = 1e-12, PI = acos(-1);
const int N = 1e6 + 9, M = 1e7 + 9, OO = 1e9 + 7, MOD = 1e9 + 7,
          MOD2 = 998244353;
const long long inf = 1e18;
bool vis[N];
int ans[N];
int main() {
  cout << fixed << setprecision(12), ios::sync_with_stdio(false),
      cin.tie(nullptr), cout.tie(nullptr);
  int n, m, l, val;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> l >> val;
    if (vis[l]) {
      if (val != ans[l]) {
        cout << -1;
        return 0;
      }
    } else {
      vis[l] = 1;
      ans[l] = val;
    }
  }
  if (!vis[1]) ans[1] = 1;
  if (ans[1] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i) cout << ans[i];
  return 0;
}
