#include <bits/stdc++.h>
using namespace std;
long long int mod1 = 998244353;
long long int mod = 1e9 + 7;
bool comp(long long int x, long long int y) {
  if (x > y) return true;
  return false;
}
long long int INF = 1e18;
long long int a[505];
long long int b[505];
pair<long long int, long long int> c[505];
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) cin >> c[i].first >> c[i].second;
  long long int ans = 0;
  vector<int> tt;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) b[j] = a[j];
    vector<int> temp;
    for (int j = 0; j < m; ++j)
      if (c[j].first <= i && c[j].second >= i) {
        for (int k = c[j].first; k <= c[j].second; ++k) b[k]--;
        temp.push_back(j + 1);
      }
    long long int maxi, mini = 0;
    maxi = mini = b[1];
    for (int j = 2; j <= n; ++j) {
      maxi = max(maxi, b[j]);
      mini = min(b[j], mini);
    }
    if (maxi - mini > ans) {
      ans = maxi - mini;
      tt = temp;
    }
  }
  cout << ans << endl;
  cout << tt.size() << endl;
  for (int i = 0; i < tt.size(); ++i) cout << tt[i] << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
